BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/index.php)
-   Visual Programming (http://bzupages.com/forumdisplay.php?f=73)
-   -   Prime number in c sharp (http://bzupages.com/showthread.php?t=16476)

thecool 17-06-2011 09:52 PM

Prime number in c sharp
 
How to write prime number in c sharp
Code:

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

namespace prime
{
class Program
{
static void Main(string[] args)
{
int no, i, flag;
flag = 1;
Console.WriteLine("Enter no. to be checked:");
no =Convert.ToInt16 ( Console.ReadLine());

for (i = 2; i <= no / 2; i++)
{
if (no % i == 0)
flag = 0;
}
if (flag == 1)
Console.WriteLine("Prime.");
else
Console.WriteLine("not Prime");
Console.ReadLine();
}

}
}



All times are GMT +5. The time now is 11:33 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.