Print first n-even no or n-odd no

Omniitstudent
Posted by Omniitstudent under C# category on | Points: 40 | Views : 1603
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//print firnst n even no
namespace ConsoleApplication25
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("input the number");
int nNum1 = Convert.ToInt32(Console.ReadLine());
int nA = 1, nC = 1;
while (nA<=nNum1)
{
if (nC%2==0)
{
Console.WriteLine(nC);
nA++;
}

nC++;
}
Console.ReadLine();
}
}
}
//===========================================================================================
//// output--5
// 2
// 4
// 6
// 8
// 10

===================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//print firnst n odd no
namespace ConsoleApplication26
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("input the number");
int nNum1 = Convert.ToInt32(Console.ReadLine());
int nA = 1, nC = 1;
while (nA<=nNum1)
{
if (nC%2!=0)
{
Console.WriteLine(nC);
nA++;
}

nC++;
}
Console.ReadLine();
}
}
}
//===========================================================================================
//// output--5
// 1
// 3
// 5
// 7
// 19

Comments or Responses

Login to post response