Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-26-2009, 01:27 PM   PM User | #1
hackerzlab
New Coder

 
Join Date: Feb 2006
Posts: 91
Thanks: 19
Thanked 0 Times in 0 Posts
hackerzlab is an unknown quantity at this point
to get 10 output in each line.

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:
Code:
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:
Code:
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.
hackerzlab is offline   Reply With Quote
Old 08-27-2009, 01:09 AM   PM User | #2
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,233
Thanks: 4
Thanked 81 Times in 80 Posts
Spookster will become famous soon enough
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.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 08-27-2009, 04:12 PM   PM User | #3
hackerzlab
New Coder

 
Join Date: Feb 2006
Posts: 91
Thanks: 19
Thanked 0 Times in 0 Posts
hackerzlab is an unknown quantity at this point
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.
hackerzlab is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:06 AM.


Advertisement
Log in to turn off these ads.