+ 1
Can anyone tell me why this is happening
This is my code --- #include<stdio.h> int main() { int a,b; printf("Enter value of a \n"); scanf("%d ", &a); printf("Enter value of b \n"); scanf("%d", &b); if (a==30) { printf("True A \n"); } else if(b==30) { printf("True B"); } else if (a+b==30) { printf("Sum is 30"); } else { printf("False"); } return 0; } In the output, I'm getting this Enter value of a 45 30 Enter value of b True B My question is why it takes input for b before printing "Enter value of b" https://code.sololearn.com/c68BXmsBx2Pe/?ref=app
6 Answers
+ 5
In 7th line remove space after %d
("%d",&a);
It waits for space so that it asking next input before print statement
+ 2
We can try that much easier if you copy+paste it into a SoloLearn "code bit". Please edit your original post to include that.
+ 1
Laukesh singh it works fine here. what compiler you use
+ 1
+ 1
Laukesh singh
I think you are printing value of b before your comments. Print like this:
printf("Enter value of b \n");
scanf("%d", &b);
printf ("%d\n", b);
0
Azhagesanヾ(˙❥˙) Vs code