Thread: Printing a line of numbers in form: +0000

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    27

    Printing a line of numbers in form: +0000

    Hello,
    I want to print a line like this using a printf statement:

    Code:
    +0000 +0000 +0000 +0000
    How can I do this using a for statement?
    Please Help!

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Show your attempt. This is your 12th post here. You know better. Stop being lazy.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    27
    i have tried numerous times, i have tried many things
    it just isn't happening

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by ahmedbatty View Post
    i have tried numerous times, i have tried many things
    it just isn't happening
    Did you try it with a for loop like you said you're supposed to? Did you figure out how to declare the main() function? Let's see it. We're not your code slaves.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    27
    There, I did it somehow.
    But I don't understand how the "%+05d" works.

    Code:
    #include<stdio.h>
    
    
    int main()
    {
    	int a = 0;
    
    
    	for( int i = 0; i <= 4; i++ )
    	{
    		printf( " %+05d ", a );
    	}
    
    
    	printf( "\n\n\n\n" );
    }

  6. #6
    Registered User
    Join Date
    Oct 2011
    Location
    Denmark
    Posts
    80
    Here you will find all the explanation about "%+05d" and many other things : www.csd.uoc.gr/~hy150b/spring-2011/lectures/secrets_of_printf.pdf

  7. #7
    Registered User
    Join Date
    Nov 2011
    Posts
    27
    Quote Originally Posted by Tibo-88 View Post
    Here you will find all the explanation about "%+05d" and many other things : www.csd.uoc.gr/~hy150b/spring-2011/lectures/secrets_of_printf.pdf
    thank you so much!

  8. #8
    Registered User
    Join Date
    Nov 2011
    Posts
    29
    Quote Originally Posted by Tibo-88 View Post
    Here you will find all the explanation about "%+05d" and many other things : www.csd.uoc.gr/~hy150b/spring-2011/lectures/secrets_of_printf.pdf
    Wow didn't know there were so many secrets. Thanks for sharing!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. double division error (I get -0.0000)
    By dorakura in forum C Programming
    Replies: 6
    Last Post: 03-07-2008, 07:33 PM
  2. How do you store very large numbers in standard form?
    By Finchie_88 in forum C Programming
    Replies: 3
    Last Post: 12-12-2007, 10:18 AM
  3. Please help me with parsing numbers form a file
    By jmmjm in forum C++ Programming
    Replies: 2
    Last Post: 07-26-2007, 03:06 AM
  4. 47.0000 = 46.9999 ?!?
    By bonkey in forum Windows Programming
    Replies: 8
    Last Post: 09-14-2002, 04:51 PM
  5. Reading text files form a certain line???
    By Agent89 in forum C++ Programming
    Replies: 4
    Last Post: 05-24-2002, 11:40 AM