0

Explain me this!

#include<stdio.h> int main(){ int subject; printf("Choose Your subject in which you have passed\n"); printf("If you have passed only Math then enter 1\n"); printf("If you have passed only Science then enter 2\n"); printf("If you have passed both Math & Science then enter 4\n"); scanf("%d" ,&subject); printf("You have entered: %d \n"); if (subject==1) { printf("You have passed only | Math | \n"); printf("You will get only 15 toffee!!"); } else if (subject==2) { printf("You have passed only | Science | \n"); printf("You will get only 15 toffee!!"); } else if (subject==4) { printf("You have passed both | Math | & | Science | \n"); printf("Hurray!! You will get only 50 toffee!!"); } else { printf("You have entered Wrong! :("); } return 0; }

14th May 2020, 5:49 AM
Subhadeep Paul
Subhadeep Paul - avatar
1 Respuesta
0
If u enter a number accordingly it will show u no of toffee u get. Eg. If u input 2 Then it will display 'passed in science' and 'you get 15 toffee' Its just a basic problem to demonstrate the use of if else if else block . Hope this helps. Thanks.
14th May 2020, 6:25 PM
Tejas Amit Sheth