How this program works: we are using sum and number variables in for loop. The user enters the numbers to for loop. Then given numbers add to “sum” for each iteration.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
class Program { static void Main(string[] args) { int number, sum = 0; Console.WriteLine(".:Sum of 10 Numbers:."); for (int i = 0; i < 10; i++) { Console.Write("Enter {0}. number:",i+1); number = Convert.ToInt32(Console.ReadLine()); sum += number; } Console.WriteLine("Sum Of 10 Numbers:{0}",sum); Console.ReadLine(); } } |
Output:
If you want to more examples click here