Write a C# program to print numbers between 1 to 100 which are divisible by 3, 5 .
The for loop counts from 1 to 100 step by step and “if statement”compares next number by 3 or 5 in the loop statement. If the condition is equal to “true”, the number will print on the screen
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
static void Main(string[] args) { Console.WriteLine("Divided by 3 & 5: "); for (int i=1;i<=100;i++) { if(i%3==0 && i%5==0) { Console.WriteLine(i); } } Console.ReadKey(); } |
Output: