In this article, we will find the Count of the numbers that are not divisible by 3,5 between 1 and N.
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, 5 whether is number or not.
In the last line we print the result of processing on the screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
static void Main(string[] args) { int counter = 0; Console.Write("n : "); int n = Convert.ToInt32(Console.ReadLine()); for(int i=1;i<=n;i++) { if(i%3!=0 && i%5!=0) { counter++; } } Console.WriteLine("Count of numbers : "+counter); Console.ReadKey(); } |
Output:
You can find more similar examples of programming for this programming language in the site.