545
In this example we will create a simple program to check if a number is an odd or even number.
We use a fairly simply formula
If a number is divisible by 2 with the remainder 0 then the number is an Even number. If the number is not divisible by 2 then that number will be an Odd number.
Example
This shows for loops and uses the modulo operator
using System; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int i = 0; Console.WriteLine("Even Numbers:"); for (i = 1; i <= 99; i++) { if (i % 2 == 0) { Console.Write(i + " "); } } Console.WriteLine("\nOdd Numbers:"); for (i = 1; i <= 99; i++) { if (i % 2 != 0) { Console.Write(i + " "); } } Console.Read(); } } }
This will display the following
Even Numbers:
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98
Odd Numbers:
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99