Write a program in C# Sharp for sum five numbers using for loop.
Sample Solution
C# Sharp Code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { Console.WriteLine("Enter Five number for sum number"); int I, sumnum, number; for (sumnum = number = I = 0; I < 5; I += 1) { number = Convert.ToInt32(Console.ReadLine()); if (number <= 0) continue; sumnum = sumnum + number; } Console.WriteLine("The sum of number is {0}",sumnum); Console.ReadLine(); } } }
The Sum is: 15
No comments:
Post a Comment