It is known that, printf() function is an inbuilt library function in C programming language in the header file stdio.h. It is used to print a character, string, float, integer etc. onto the output screen. However, while printing the float values, the number of digits following the decimal point can be controlled by the user. One of the ways to do that is by using formats like %.2f etc. But variables can also be used for formatting format specifiers.
Below example shows how this can be done.
This article is contributed by MAZHAR IMAM KHAN. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- Understanding constexpr specifier in C++
- C++ final specifier
- Can we access global variable if there is a local variable with same name?
- Set a variable without using Arithmetic, Relational or Conditional Operator
- Format specifiers in C
- Format specifiers in different Programming Languages
- Program to convert time from 12 hour to 24 hour format
- Variable Length Arrays in C and C++
- Different ways to declare variable as constant in C and C++
- Different ways to initialize a variable in C/C++
- Efficient ways to compare a variable with multiple values
- Print pattern using only one loop | Set 1 (Using setw)
- Count number of unique Triangles using STL | Set 1 (Using set)
- How will you print numbers from 1 to 100 without using loop?
- Print "Even" or "Odd" without using conditional statement
- Can we access private data members of a class without using a member or a friend function?
- How to check whether a number is in the range[low, high] using one comparison ?
- Print individual digits as words without using if or switch
- Database Connectivity using C/C++
- How to find size of array in C/C++ without using sizeof ?