Thread: newline loop

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    22

    newline loop

    Code:
    #include <stdio.h>
    #include <math.h>
    
    int isprime(int n); 
    
    int main(void)
    {
    int i; 
    int count=1; 
    printf( "The prime numbers from 1 to 1000 are \n" );
    for ( i = 2;i < 1000;i++){
    	if (isprime(i) && count%10!=0)
    		printf("%d\t",i);
    		count++;
    	if (isprime(i) && count%10==0) 
    		printf("%d\n",i);
    		count++;
    }}
    int isprime( int n )
    {
    int sroot = sqrt(n);
    int i;
    for ( i = 2;i <= sroot;i++){
    	if (n % i == 0)
    		{return 0;}
    	}
    return 1;
    }
    i want a newline to be created after every 10th prime number and the if statements for int count do not work. Suggestions?
    Last edited by lancehumiston; 04-01-2011 at 01:11 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. A somewhat bizzare problem!!! - WHILE LOOP
    By bobthebullet990 in forum C Programming
    Replies: 3
    Last Post: 03-31-2006, 07:19 AM
  4. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM
  5. comparing int to newline character
    By RedZippo in forum C++ Programming
    Replies: 5
    Last Post: 05-13-2004, 06:37 PM

Tags for this Thread