#include <stdio.h>
int *getPrimes(int n) {
static int r[10];
int i,j;
int count = 0, s=0;
for(i = 2 ; i <= n-1 ; i++)
{
for(j = 1 ; j <= i ; j++)
{
if((i%j)==0)
{
count++;
}
}
if(count == 2)
{
r[s] = i;
s++;
}
count = 0;
}
return r;
}
int main () {
int *p;
int i;
// int n=100;
int count = 0;
printf("enter number");
scanf("%d",&n);
p = getPrimes(n);
for ( i = 0; i <n ; i++ )
{
count++;
printf( "%d\n",p[i]);
if(p[i] == 0)
{
break;
}
}
return 0;
}
int *getPrimes(int n) {
static int r[10];
int i,j;
int count = 0, s=0;
for(i = 2 ; i <= n-1 ; i++)
{
for(j = 1 ; j <= i ; j++)
{
if((i%j)==0)
{
count++;
}
}
if(count == 2)
{
r[s] = i;
s++;
}
count = 0;
}
return r;
}
int main () {
int *p;
int i;
// int n=100;
int count = 0;
printf("enter number");
scanf("%d",&n);
p = getPrimes(n);
for ( i = 0; i <n ; i++ )
{
count++;
printf( "%d\n",p[i]);
if(p[i] == 0)
{
break;
}
}
return 0;
}
Thank You, for such useful information.
ReplyDeleteYour posts are always easy to understand and Helpful.