1printf("%0k.yf" float_variable_name)
2
3Here k is the total number of characters you want to get printed. k = x + 1 + y (+ 1 for the dot) and float_variable_name is the float variable that you want to get printed.
4
5Suppose you want to print x digits before the decimal point and y digits after it. Now, if the number of digits before float_variable_name is less than x, then it will automatically prepend that many zeroes before it.
1it is used during taking input and out put
2
3Int ("%d"):
4Long ("%ld"):
5Char ("%c"):
6Float ("%f"):
7Double ("%lf")
8
9example:
10
11char ch = 'd';
12double d = 234.432;
13printf("%c %lf", ch, d);
14
15char ch;
16double d;
17scanf("%c %lf", &ch, &d);
1follow this for best answer with example:
2---------------------------------------------
3https://www.freecodecamp.org/news/format-specifiers-in-c/
4https://www.tutorialspoint.com/format-specifiers-in-c
1/* printf example in C */
2#include <stdio.h>
3
4int main()
5{
6 printf ("Characters: %c %c \n", 'a', 65);
7 printf ("Decimals: %d %ld\n", 1977, 650000L);
8 printf ("Preceding with blanks: %10d \n", 1977);
9 printf ("Preceding with zeros: %010d \n", 1977);
10 printf ("Some different radices: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
11 printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
12 printf ("Width trick: %*d \n", 5, 10);
13 printf ("%s \n", "A string");
14
15 return 0;
16}
17
18
19//*******
20
21Characters: a A
22Decimals: 1977 650000
23Preceding with blanks: 1977
24Preceding with zeros: 0000001977
25Some different radices: 100 64 144 0x64 0144
26floats: 3.14 +3e+000 3.141600E+000
27Width trick: 10
28A string