Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

why we use % in printf in c++

+1 vote
asked Sep 23, 2021 by bakr Yaish (130 points)
an example

  ;  printf ("Ceil is : %e\n", ceil(x) )

1 Answer

0 votes
answered Sep 23, 2021 by Peter Minarik (86,180 points)

printf() is used to print something to the standard output (console). If you want to display something static, that doesn't change, you can just put it into the argument:

printf("Hello World!\n");

However, if you would like to have there something that you do not know what exactly it is when you write the code (e.g. a result of a calculation), then you can include the value of variables to be displayed on the standard output as well. Just like in your example you use the scientific notation (%e) to print the ceiling of x.

Please, check the printf() to see all the available format options (e.g. integral numbers, floating point numbers, strings, pointers, hexadecimal numbers, etc).

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...