//format specifers - it a way to tell the compiler what type of data is in variable during taking input,displaying output to the user*/
// character format specifers
#include <stdio.h>
int main()
{
char ch[] = "satyam"; //[empty]-it contains infinite value [12]- it contains character upto 12 letters
printf("%s\n", ch); //%s -is for words or line
return 0;
}
#include <stdio.h>
int main()
{
char ch = 's'; // for single letter 'letter' is used while "letter" shows error
printf("%c\n", ch); // %c - is for single letter
return 0;
}
// Integer format specifiers
#include <stdio.h>
int main()
{
int x = 45, y = 90;
printf("%d\n", x); //%d &%i - do the same thing
printf("%i\n", x);
return 0;
}
// Floating point specifers
#include <stdio.h>
int main()
{
float a = 12.67;
printf("%f\n", a);
printf("%e\n", a);
printf("%E\n", a);
return 0;
}
// example
#include <stdio.h>
int main()
{
char str[] = "geeksforgeeks";
printf("%20s\n", str);
printf("%-20s\n", str);
printf("%20.5s\n", str);
printf("%-20.5s\n", str);
return 0;
}
#include<stdio.h>
int main()
{
float a=7.333;
printf("%8.4f",a); // %8 means it insert 8 space before decimal including 7 & .4 means it insert 4 digit after decimal
return 0;
}
#include<stdio.h>
int main()
{
float a=7.333;
printf("%-8.4f satyam",a); // %-8 means it insert 8 space after decimal including 3330 & .4 means it insert 4 digit after decimal
return 0;
}
/*1.%u for an unsigned integer.
2.%lld for long long int.
3.%o octal integer without leading zero
4.%x hexadecimal integer without 0x before the number
*/
Comments
Post a Comment