C# Program to Calculate sum of all numbers divisible by 3 in given range.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
static void Main(string[] args) { int sum = 0; Console.Write("Number 1 : "); int num1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Number 2 : "); int num2 = Convert.ToInt32(Console.ReadLine()); for(int i=num1;i<=num2;i++) { if(i%3==0) { sum += i; } } Console.WriteLine("Sum of Numbers "+sum); Console.ReadKey(); } |
Output:
You can find more similar examples of programming for this programming language in the site.