+ 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

27th Mar 2022, 5:17 AM
Laukesh singh
Laukesh singh - avatar
6 Respostas
+ 5
In 7th line remove space after %d ("%d",&a); It waits for space so that it asking next input before print statement
27th Mar 2022, 6:03 AM
Azhagesanヾ(✿)
Azhagesanヾ(✿) - avatar
+ 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.
27th Mar 2022, 5:34 AM
HungryTradie
HungryTradie - avatar
+ 1
Laukesh singh it works fine here. what compiler you use
27th Mar 2022, 5:57 AM
Azhagesanヾ(✿)
Azhagesanヾ(✿) - avatar
27th Mar 2022, 6:18 AM
Laukesh singh
Laukesh singh - avatar
+ 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);
27th Mar 2022, 6:20 AM
A͢J
A͢J - avatar
27th Mar 2022, 5:59 AM
Laukesh singh
Laukesh singh - avatar