#include<conio.h>
#include<time.h>
#include<dos.h>
#include<math.h>
#include<iostream.h>
long isprime( long n){
long no =n;
long sw=0;
for(long i = 2;i<(sqrt(n)+1);i++){
//for(long i = 2;i<n;i++){
if(no%i==0){
sw =1;
break;
}}
if(sw==1)
return 0;
return 1;
}
void main(){
clrscr();
time_t t1 , t2;
time(&t1);
long l,u;
cout<<"\n Enter lower range : ";
cin>>l;
cout<<"\n Enter upper range : ";
cin>>u;
cout<<"\n From "<<l<<" to "<<u<<" the following numbers are prime : \n";
for(long i=l;i<=u;i++){
if(isprime(i))
cout<<i<<"\t";
}
time(&t2);
cout<<"The difference is "<<difftime(t2,t1);
getch();
}
#include<time.h>
#include<dos.h>
#include<math.h>
#include<iostream.h>
long isprime( long n){
long no =n;
long sw=0;
for(long i = 2;i<(sqrt(n)+1);i++){
//for(long i = 2;i<n;i++){
if(no%i==0){
sw =1;
break;
}}
if(sw==1)
return 0;
return 1;
}
void main(){
clrscr();
time_t t1 , t2;
time(&t1);
long l,u;
cout<<"\n Enter lower range : ";
cin>>l;
cout<<"\n Enter upper range : ";
cin>>u;
cout<<"\n From "<<l<<" to "<<u<<" the following numbers are prime : \n";
for(long i=l;i<=u;i++){
if(isprime(i))
cout<<i<<"\t";
}
time(&t2);
cout<<"The difference is "<<difftime(t2,t1);
getch();
}
No comments:
Post a Comment