In this article we find the list and count of the numbers between 1,100 that numbers are divisible by 3, 7.
In this example we used for loop and if statement for solve the issue.
Variables are defined in the first row. In the next lines, values are assigned to these variables. In the loop “if statement” checks the number is divisible by 3, 7 whether is number or not.
In the last line we print the result of processing on the screen.
Source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
class Program { static void Main(string[] args) { int counter = 0; Console.Write("n : "); int n = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("list of the numbers that are not divisible by 3,7 between 1 and "+n); Console.WriteLine("====================================================================="); for(int i=1;i<=n;i++) { if(i%3==0 && i%7==0) { Console.Write(i+" "); counter++; } } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Count of numbers : "+counter); Console.ReadKey(); } } |
Output:
You can find more similar examples of programming for this programming language in the site.