At Table 1 output is correct but at Table 2 I just change the position of prntf (age) Plz solve this problem why output is error Thank You 1) #include <stdio.h> #include <stdlib.h> int main(){ float average; char sex; int age; printf("Enter your sex\n"); scanf("%c",&sex); printf("Enter your age\n"); scanf("%d",&age); printf("Enter your average\n"); scanf("%f",&average); printf("you have entered your age %d average %f and sex %c",age,average,sex); return 0; } o/p- Enter your sex m Enter your age 18 Enter your average 32.2 you have entered your age 18 average 32.200001 and sex m This is Correct 2) #include <stdio.h> #include <stdlib.h> int main(){ float average; char sex; int age; printf("Enter your age\n"); scanf("%d",&age); printf("Enter your sex\n"); scanf("%c",&sex); printf("Enter your average\n"); scanf("%f",&average); printf("you have entered your age %d average %f and sex %c",age,average,sex); return 0; } o/p- Enter your age 18 Enter your sex Enter your average m you have entered your age 18 average 0.000000 and sex This is wrong
You need a space before “%c”. The reason for the same is explained here https://www.codesdope.com/discussion/why-are-you-using-a-space-before-c-in-scanf-c-ch/