This question already has answers here:
How do I print the percent sign(%) in C? [duplicate]
(4 answers)
Closed 7 years ago.
I was just completing my assignment when I noticed that the text after the % symbol in double quotes is not printing. Here is a very easy example to show this:
//program
#include<stdio.h>
int main()
{
printf("remainder of 5%2 is : %d",5%2);//here %2 is not printing
return 0;
}
output:
remainder of 5 is : 1
Only the %2 is not printed by printf() rest everything is fine.
Use %% to print %:
printf("remainder of 5%%2 is : %d",5%2);
You can also use ASCII code:
printf("remainder of 5%c2 is : %d",37,5%2");
Related
This question already has answers here:
Why the result of pow(10,2) 99 instead of 100? [duplicate]
(1 answer)
Strange behaviour of the pow function
(5 answers)
Closed 28 days ago.
when i use pow() function in Vscode editior it works properly for all digits execpt 5 and its mulitples
#include<stdio.h>
#include<math.h>
int main(){
int a = 25;
int b = pow(a,2);
printf("%d",b);
return 0;
}
This question already has answers here:
format string used in printf function in C programming
(2 answers)
Closed 7 months ago.
when you write code such as
printf("Average score: %f\n", (score[0] + score[1] + score[2]) / 3.0);
what is the point of the %f , is it needed?, i know that sometimes you change the letter after it, what are ways you can use the %?
that's a print formatter. "f" is for floats (decimals). the % is used when you want to put a variable value in a printf statement. So % followed by a letter (f,d,c,s,p, etc) indicates the type.
This question already has answers here:
Printing leading 0's in C
(11 answers)
Closed 2 years ago.
my question is short, if I have the following 2 lines of code:
int var = 01;
printf("%d", var);
the output is : 1
how do I get 01 rather than 1?
Use left padded format string.
Solution
int var = 1;
printf("%02d", var);
This question already has answers here:
What does "%.*s" mean in printf?
(4 answers)
Closed 6 years ago.
Why the following program work ? & what is difference b/w %d vs %*d ?
#include<stdio.h>
int main()
{
int n=5;
printf("n=%*d\n", n, n);
return 0;
}
What does width meant here by ?
The first n belongs to the * in %*d, so for your example it is %5d. %5d means to print an integer of width 5. Example: 234 is printed as __234 (2 spaces)
This question already has answers here:
C conditional operator ('?') with empty second parameter [duplicate]
(6 answers)
Closed 9 years ago.
#include<stdio.h>
int main()
{
printf("%d\n", 4 ?: 8);
}
According to the C standard this program is invalid because it is missing an expression between the ? and :.But The interesting thing is that there is when I compile the code it is printing 4.how come it will print 4 rather than showing any compile error
This is a gcc extension.
x ? : y
is equivalent to
x ? x : y
See here for detail.