write the prime no program in c++?

Answer Posted / tuhin pal chowdhury

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num;
int flag = 0;
cout<<"Enter a number"<<endl;
cin>>num;
for(int i=2;i<num;i++)
{
if((num%i) == 0)
{
flag = 1;
break;
}
}
if (flag == 1)
cout<<"Not Prime"<<endl;
else
cout<<"Prime"<<endl;
getch();
}

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is virtual base class?

760


How is data hiding achieved in c++?

784


What is the use of seekg in c++?

798


What is the latest version on c++?

870


Can member data be public?

778


What is exception handling? Does c++ support exception handling?

794


What is an overflow error?

830


How do you initialize a string in c++?

743


Write a short code using c++ to print out all odd number from 1 to 100 using a for loop

795


What are single and multiple inheritances in c++?

778


How do we implement inheritance in c++?

824


What is the difference between delegation and implemented-in-terms-of?

787


What are separators in c++?

821


What are pointers, when declared, intialized to a) NULL b) Newly allocated memory c) Nothing. Its random

887


How to declare a function pointer?

767