C language practice On line 25 (see below) it says that "unknown conversion type character 'y' in format", why is that?? and also, I don't think 'x/y' is not working right, so I used another variable z to represent it but I guess it doesn't work either (it keeps showing x=0)
#include <stdio.h> #include<math.h> #include<stdlib.h> int main( int argc, char ** argv ) { int x; int y; int z; z= x / y; printf("Enter x value: \n"); fflush(stdout); scanf("%d",&x); printf("Enter y value: \n"); fflush(stdout); scanf("%d",&y); printf("Results: \n"); printf("x value\t |y value|expressions \t | results \n"); printf("%d \t | %d \t | x=y+3 \t | x= %d\n", x, y, y+3); printf("%d \t | %d \t | x=y-2 \t | x= %d\n", x, y, y-2); printf("%d \t | %d \t | x=y*5 \t | x= %d\n", x, y, y*5); printf("%d \t | %d \t | x=x/y \t | x= %d\n", x, y, z); printf("%d \t | %d \t | x=x % y \t | x= %d\n", x, y, x % y); return 0; }
line 25 is printf("%d \t | %d \t | x=x % y \t | x= %d\n", x, y, x % y);
Is there any other way to write this in a shorter way?
That is already pretty short.
The percent sign is a meta-character in printf format strings. To use a percent sign as a regular character, it must be escaped. The escape character in printf format strings is the percent sign, so: printf("%d \t | %d \t | x=x %% y \t | x= %d\n", x, y, x % y);
Aah I see! Thank you again rsmith :D Thanks also e.mccormick for letting me know :)
Join our real-time social learning platform and learn together with your friends!