hello keerthi...u asked me right..?
here is the solution for ur doubt in "to check whether the given number is prime or not...?"....in c++
note:
(1). the words with red color letters are comments to understand the concept..need not include it in program...ok..?
(2). prime number is the number which is divisible by 1 and by itself...like 1,2,3,5,7,11,13,17,19,23..etc...so have this logic in ur mind and write the program..definetly u finds it easy...here is the program.,hope it is helpful..
PROGRAM CODING:
#include<iostream.h>
#include<conio.h>
int main()
{
int flag;
int n,i;
cout<<"Enter the number:"; /*you are getting number from the user here*/
cin>>n;
if(n<=3)/*if it is 0,1,2,3--it will be obviously prime number.,so we are declaring this as prime*/
cout<<"The number is a prime number";
else
for(int i=2;i<n/2;i++)/*these steps are checkin whthr the given no. is divisible by othr no.s or not.,(continue)*/
{if(n%i==0)
{
flag=0;/*if yes.,it will print "it is not a prime"*/
break;
}
else
flag =1;/*if not.,it will print"it is a prime"*/
}if(flag==1)
cout<<"The given number is a prime number";
else
cout<<"The given number is not a prime number";
getch();
}
here is the solution for ur doubt in "to check whether the given number is prime or not...?"....in c++
note:
(1). the words with red color letters are comments to understand the concept..need not include it in program...ok..?
(2). prime number is the number which is divisible by 1 and by itself...like 1,2,3,5,7,11,13,17,19,23..etc...so have this logic in ur mind and write the program..definetly u finds it easy...here is the program.,hope it is helpful..
PROGRAM CODING:
#include<iostream.h>
#include<conio.h>
int main()
{
int flag;
int n,i;
cout<<"Enter the number:"; /*you are getting number from the user here*/
cin>>n;
if(n<=3)/*if it is 0,1,2,3--it will be obviously prime number.,so we are declaring this as prime*/
cout<<"The number is a prime number";
else
for(int i=2;i<n/2;i++)/*these steps are checkin whthr the given no. is divisible by othr no.s or not.,(continue)*/
{if(n%i==0)
{
flag=0;/*if yes.,it will print "it is not a prime"*/
break;
}
else
flag =1;/*if not.,it will print"it is a prime"*/
}if(flag==1)
cout<<"The given number is a prime number";
else
cout<<"The given number is not a prime number";
getch();
}

.jpg)







