TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Aditya Varma Mudunuri
NA
58
104.5k
How to Solve the Code Whether Entered Number is Prime or Not
Dec 10 2013 8:07 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Console1
{
class PrimeNumber
{
static void Main(string[] args)
{
int num,a;
int flag;
Console.WriteLine("Enter any number");
num = int.Parse(Console.ReadLine());
if (num == 0 || num == 1)
{
Console.WriteLine("Given Number is Not a Prime Number");
}
else
{
for (a = 2; a <= num; a++)
{
flag = 0;
if (num % a == 0)
flag = 1;
//Console.WriteLine("{0} is Not a Prime Number", num);
return;
}
//Console.WriteLine("{0} is a Prime Number", num);
if (flag == 1)
{
Console.WriteLine(num + " is not Composite Number");
}
else
Console.WriteLine(num + "is a Prime Number");
}
/*if (flag == 1)
{
Console.WriteLine(num + " is not Composite Number");
}
else
Console.WriteLine(num + "is a Prime Number");*/
}
}
}
Reply
Answers (
2
)
open window modal dialog
bulid the filter ( huogh transform )