use of for statement in C#
For Example: Write a program to
demonstrate the use of for statement.
(2, 3,
5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89 and 97.)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
classProgram
{
staticvoid Main(string[] args)
{
int i = 1;
int no = 1;
Console.WriteLine("Enter any number
:");
no =
Convert.ToInt32(Console.ReadLine());
for (i=2;i<no;i++)
{
if (no%i==0)
break;
}
if (i==no)
{
Console.WriteLine("{0} is a Prime
Number", no);
Console.ReadLine();
}
else
{
Console.WriteLine(" {0} is Not
prime number", no);
Console.ReadLine();
}
}
}
}
Output:

Comments
Post a Comment