Rabu, Februari 19, 2014

Make New Line On C Programming

To make new line on C pemrogramming, can be used syntax:

printf("\n");

or by add \n at end of content of printf() function

Example make new line on C programming:
  1. Open Dev C++
  2. File menu > New > Source File, then will be created a new worksheet titled Untitled1
  3. File menu > Save As. On Save as type: choose C source files (*.c) and on File name, example we give name example make new line.c
  4. First, type minimal required syntax on C programming:

    main(){}

  5. Add getch() function in main() function to show program result while be Run, so that program syntax be:

    main(){
           getch();
           }


  6. For example we make 3 printf function, example program syntax be:

    main(){
           printf("Hello World");
           printf("Is it still safe there?");
           printf("Always keep your prayer!");
           getch();
           }


    after be Compiled and Run then will show its result as follow:


    Can be seen "Hello World" lettering coincide with "Is it still safe there?" lettering and coincide with "Always keep your prayer!" lettering. How so that three lettering/sentences is located at different line? Example we want program result as follows:

    Hello World
    Is it still safe there?
    Always keep your prayer!


  7. The way is by add printf("\n") function at before printf() function of sentence/character want to located at new line, so that program syntax be:

    main(){
           printf("Hello World");
           printf("\n");
           printf("Is it still safe there?");
           printf("\n");
           printf("Always keep your prayer!");
           getch();
           }


    Now try to Compile dan Run program, then will show its result as follows:


    Writing of the printf("\n") function can be simplified by add \n at end of printf() content to make new line for next printf content, so that porgram syntax be:

    main(){
           printf("Hello World \n");
           printf("Is it still safe there? \n");
           printf("Always keep your prayer!");
           getch();
           }


    Try to Compile and Run, still same its result like before, right?

    Syntax above can be simplified again only use one printf function, i.e. by locate \n code between sentence, then sentence located after \n code will locate at new line, so that program syntax be:

    main(){
           printf("Hello World \nIs it still safe there? \nAlways keep your prayer!");
           getch();
           }


    Try Compile and Run, still same its result like before, right?

So, now we can make new line on C programming, that's all friends...
If there is something understood, please ask... ! : ) thank you...

0 komentar: