simply use of two for loop and if else operator
condition " i%j==0 "helps to determine the Prime no. Any further query leave message....
Source Code:-
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int n,count=0;
cout<<"PRIME NO. SERIES by-Tarun Rawat\n";
cout<<"\nINPUT THE VALUE OF N: " ;
cin>>n;
cout<<"\nTHE PRIME NO. SERIES B/W 1 TO"<<n<<"\n";
for(int i=1;i<=n;i++)
{for(int j=1;j<=i;j++)
{ if(i%j==0)
count++;
}
if (count==1||count==2)
cout<<i<<" ";
count=0;
}
getch();
}
No comments:
Post a Comment