Hello Guys! Welcome To My Blog!
Print Even And Odd In C# With Use Of Only One Loop
Today We will be Learn How to Print Even Odd ,it is very simple to use two loop..
But how we can print even odd with One loop Its difficult little bit but Not Hard!
using System;
namespace evenodd
{
class Program
{
static void Main(string[] args)
{
int i;
string even = "Even number\n";
string odd = "Odd number\n";
for (i = 1; i <= 10; i++)
{
if (i % 2 == 0)
{
even += i + "\n";
}
else { odd += i + "\n"; }
}
Console.WriteLine(even);
Console.WriteLine(odd);
Console.ReadLine();
}
}
}
OUTPUT!
Even number
2
4
6
8
10
Odd number
1
3
5
7
9
Comments
Post a Comment