Sunday, November 3, 2013

Printing string in various ways using printf()


You can use printf() function to print the string in your program as follows:
Program 9:

#include <stdio.h>
#include <conio.h>
void main(/* Program execution begins here. */)
{
     clrscr();
     printf(“\nNever give up on anybody.”);
     printf(“\n%s”,”Never give up on anybody.”);
     printf(“\nNever” “ give” “  up” ”  on” “  anybody.”);
     printf(“\nNever\
    give\
    up\
    on \
    anybody.”);
    getch();

}

Output:

The extra spaces on the last printf() can be adjusted by using the escape sequences “\b”. So, the improved version of the printf() would be:

printf(“\nNever\
    \b\b give\
    \b\b up\
    \b\b on \
    \b\b anybody.”);

No comments:

Post a Comment