Results 1 to 5 of 5

Thread: Why we use \n in "C" language?

  1. #1
    Join Date
    Dec 2011
    Posts
    39

    Why we use \n in "C" language?

    I am new to programming as just started FYJC IT and was trying to run one simple C program. As far as I know that "\n" in C language is used to give the break lines but in my case, it is not working as expected. here is the code that I am trying to execute.
    #include<stdio.h>
    int main()
    {
    int a=2,b=3,c,d;
    float p,q;
    c=a/b*b;
    d=b/a*a;
    p=a/b*b;
    q=b/a*a;
    printf("%d %d %f %f\n",c,d,p,q);
    return 0;
    }
    When I compiled this program then I get the output as

    0 2 0.000000 2.000000

    I am not able to understand that why \n is not breaking the output. Also, provide me some more information about the "\n" in C language.

  2. #2
    Join Date
    Nov 2010
    Posts
    73

    Re: Why we use \n in "C" language?

    Welcome to IT. Its a small mistake that you did. You have placed the \n in the end and because of that the pointer of goes to next line after printing the entire output. If you want break after each value then you will have to place \n after every value to be printed. i.e printf("%d\n%d\n..."); good luck with your studies.

  3. #3
    Join Date
    Nov 2010
    Posts
    86

    Re: Why we use \n in "C" language?

    The best book that I can recommend you for better understanding of the C is "Let us C". This is the best among all the books for the C and you must get this book to clear your doubts. I dont think that you will require any additional note if you have this book.

  4. #4
    Join Date
    Aug 2011
    Posts
    367

    Re: Why we use \n in "C" language?

    Whichever book you prefer, make sure that you do the practical exercise of the programs that you have learned and this will make you better understand the language.

  5. #5
    Join Date
    Jun 2011
    Posts
    308

    Re: Why we use \n in "C" language?

    you can also refer the The ANSI C Programming Language and it will be better for you fif you get the second addition of this book.

Similar Threads

  1. Replies: 3
    Last Post: 14-01-2014, 09:46 AM
  2. Replies: 6
    Last Post: 10-01-2011, 10:49 PM
  3. Replies: 3
    Last Post: 18-12-2010, 03:36 PM
  4. Replies: 6
    Last Post: 18-05-2010, 12:27 AM
  5. Replies: 5
    Last Post: 17-12-2008, 09:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,724,372.45432 seconds with 17 queries