1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C programming question

  1. Feb 25, 2013 #1
    All i have to do is write a program that will output my initials (JBL) in block letters.

    This is what i have done:

    Code (Text):

    #include <stdio.h>
    void main()
    {
    printf("     JJJJJJ  BBBBBBBB  LLL");
    printf("       JJ     BB    BB    LLL");
    printf("       JJ    BBBBBBB    LLL");
    printf("       JJ    BB    BB     LLL");
    printf("      JJ JJ     BB    BB    LLLLLLLL");
    printf("    JJJJJ    BBBBBBBB  LLLLLLLL");
    }
     
    Now this is wrong of course. When i execute, it will print the top line with the correct number of spaces, but after the first LLL it just goes wack. I assume it is because i am not telling it when to start a new line, right? If so, how do i do that? Also, could i just use 1 printf statement instead of 6?
    Thanks
     
    Last edited by a moderator: Feb 26, 2013
  2. jcsd
  3. Feb 25, 2013 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    The newline character '\n' should be added inside the "" of the printf string:

    printf(" This is a line of text.\n");
     
  4. Feb 25, 2013 #3
    ahh perfect. Thank you. another problem i was having was i didn't know tab would act as a single space, so it was printing all messed up. Got it now. Thanks SteamKing
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: C programming question
  1. C programming question (Replies: 7)

  2. C programming question (Replies: 22)

  3. C programming question (Replies: 1)

  4. C programming question (Replies: 2)

  5. C programming question (Replies: 4)

Loading...