Right Click to Search

Wednesday, March 24, 2025

Different Ways of Formatting Printf in C



Different Ways of Formatting Printf in C

1.Display Normal Message
printf("Hello Welcome to C");

2.Display Space
printf("\t");

3.Display New Line
printf("\n");

4.Printing Value of Variable
printf("Addition of two Numbers : %d",sum");

5.Multiple Format Specifiers
printf("I Love %c %s",'c',"Programming");
Output :
I Love c Programming

6.Display Integer In Different Styles (- is space)
printf("%d",1234);
printf("%3d",1234);
printf("%6d",1234);     
printf("%-6d",1234);
printf("%06d",1234);
Output :
1 2 3 4
1 2 3 4
- - 1 2 3 4
1 2 3 4 - -
0 0 1 2 3 4

7.Display String In Different Format
char str[]="Programming";    // Length = 11
printf("%s",str);    // Display Complete String
printf("%10s",str);  // 10 < Length therefor Display Complete String
printf("%15s",str);  // Display Complete String with 4 spaces Alignment:Right
printf("%-15s",str);   //Same of Above But Justification = Left
printf("%15.5s",str);  //15-5 = 10 spaces and show first 5 characters Align : R  
printf("%-15.5s",str); //15-5 = 10 spaces and show first 5 characters Align : L
Output :(-) is space
Programming
Programming
----Programming
Programming----
----------Progr
Progr----------


Bookmark & Share

Tags / Keywords : | ,

Stumble
Delicious
Technorati
Twitter
Facebook

0 Comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email

 

Learn C Programming Copyright © 2010 LKart Theme is Designed by Lasantha, Free Blogger Templates