computerstechnologydevdora.blogspot.in
devgroupindia.webs.com
#include<iostream> // based on the principle of prime,odd,even numbers
using namespace std;
#include<conio.h>
#include<math.h>
int j=0,s=1;bool prime(int num);
int random(int k);
int main()
{ int d=100,i,num;
cout<<"Enter any number :";
cin>>num;
cout<<"random numbers generated\n";
for( i=num;i<d;)
{ cout <<abs(i)<<" ";i=random (i);}
getch();
}
int random(int k)
{
if (prime(k))
return (k- ++j);
else if (k%2!=0){
return (k+ ++s);}
else
return k+ ++j;
}
bool prime(int num)
{int c=1;for(int i=2;i<=num;i++)
if(num%i==0)
++c;
if (c==2)
return 1;
else
return 0;
}
No comments:
Post a Comment