-->
Showing posts with label C Programming Basics. Show all posts
Showing posts with label C Programming Basics. Show all posts

Wednesday, June 25, 2025

Table Formatting in C Programming with right and left alignment | Format Specifier Examples with Code

 


C program collection


C program to print the number in the formatted form

//table formatting program in c

#include<stdio.h>

int main()

{

//header part

printf("| %-10s | %-13s | %-11s\n","name","age","address");

printf("| %-12s | %-12d | %-12s\n","Ram",22,"ktm");

printf("| %-12s | %-12d | %-12s\n","sam",24,"pkh");

printf("| %-12s | %-12d | %-12s\n","Raj",27,"bkh");

return 0;

}

output:-

C program to format table


string Formatting in C Programming | Format Specifier Examples with Code

 

C program collection


C program to print the number in the formatted form

//string formatting in c program

#include<stdio.h>

int main()

{

char name[]="Radhekrishna";

char name1[]="krishna";

printf("name=%s\n",name);

printf("[%20s]-right alignment\n",name);

printf("[%-20s]-left alignment\n",name);

printf("[%.3s]-only three characters.\n",name1);

printf("[%s]-all characters\n",name1);

return 0;


}


C program to format the string


Number Formatting in C Programming | Format Specifier Examples with Code

 C program collection


C program to print the number in the formatted form


//number formatting in program

#include<stdio.h>

int main()

{

int num=3453;

float pi=3.141592;

printf("default=%d\n",num);

printf("10 character width=[%10d]\n",num);

printf("left aligned:[%-8d]\n",num);

printf("default:%f\n",pi);

printf("10 width with 4 decimal:[%12.4f]\n",pi);

printf("exponential form:%.3e\n",pi);

return 0;

}


c program to format the number in output