hackerzlab
08-26-2009, 01:27 PM
i'm writing a code which is to be shown in such a way that there are 10 prime numbers in each line.
here's the code but it displays everything in one line:
main ()
{
int r1=1,r2,s,p,c,flag;
printf ("\n Enter the Range : ");
scanf ("%d",&r2);
printf ("\n The Prime Numbers in the Given range are : \n");
for (s=r1;s<=r2;s++)
{
flag =0;
for (p=2;p<s;p++)
{
c=s%p;
if (c==0)
{
flag=1;
break;
}
}
if ((flag==0) && (s!=1))
printf ("\t %d",s);
}
}
i couldn't figure a way out to have the out in lines of 10 digits each.
for example:
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97
any help would be greatly appreciated.
here's the code but it displays everything in one line:
main ()
{
int r1=1,r2,s,p,c,flag;
printf ("\n Enter the Range : ");
scanf ("%d",&r2);
printf ("\n The Prime Numbers in the Given range are : \n");
for (s=r1;s<=r2;s++)
{
flag =0;
for (p=2;p<s;p++)
{
c=s%p;
if (c==0)
{
flag=1;
break;
}
}
if ((flag==0) && (s!=1))
printf ("\t %d",s);
}
}
i couldn't figure a way out to have the out in lines of 10 digits each.
for example:
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97
any help would be greatly appreciated.