Q:

C# program to print Even and Odd numbers from 1 to 30

belongs to collection: C# Basic Programs | Looping programs

0

C# program to print Even and Odd numbers from 1 to 30

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    
    class Program
    {
        static void Main(string[] args)
        {
            int i     = 0;

            Console.WriteLine("Even Numbers :");
            for (i = 1; i <= 30; i++)
            {   
                if( i%2 == 0 )
                {
                    Console.Write(i + " ");
                }
            }

            Console.WriteLine("\nOdd Numbers :");
            for (i = 1; i <= 30; i++)
            {
                if (i % 2 != 0)
                {
                    Console.Write(i + " ");
                }
            }

            Console.WriteLine();
        }
    }
}

Output

Even Numbers :
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
Odd Numbers :
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Define Armstrong numbers and write program to chec... >>
<< C# program to find out the leap years from 1900 to...