View Full Version : to get 10 output in each line.

08-26-2009, 02: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++)
if (c==0)
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.

08-27-2009, 02:09 AM
Seems pretty simple and straightforward. Inside your loop you'll need to keep a count of how many numbers have been computed and maybe set a boolean flag that lets you know each time 10 numbers have been computed. Since you only care about every tenth number just reset the count each time it hits 10. You will also need a conditional block that checks that flag and then either executes a print statement with a carriage return else one without.

08-27-2009, 05:12 PM
thanx for the reply.

could you please help me with the code. i cant seem to figure out what you are trying to say. besides, m not so good with the codes.