Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Assignment 5 Structured programming
- //Question 1
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char grade;
- printf("Enter grade: ");
- scanf("%c", &grade);
- switch(grade)
- {
- case 'A':
- case 'a':
- printf("Excellent");
- break;
- case 'B':
- case 'b':
- printf("Very good");
- break;
- case 'C':
- case 'c':
- printf("Good");
- break;
- case 'D':
- case 'd':
- printf("Poor");
- break;
- case 'F':
- case 'f':
- printf("Failed");
- break;
- default:
- printf("Invalid");
- }
- }
- //Question 2
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int month;
- printf("Enter number of month: ");
- scanf("%d", &month);
- switch (month)
- {
- case 1:
- printf("January: 31 days");
- break;
- case 2:
- printf("February: 28 days");
- break;
- case 3:
- printf("March: 31 days");
- break;
- case 4:
- printf("April: 30 days");
- break;
- case 5:
- printf("May: 31 days");
- break;
- case 6:
- printf("June: 30 days");
- break;
- case 7:
- printf("July: 31 days");
- break;
- case 8:
- printf("August: 31 days");
- break;
- case 9:
- printf("September: 30 days");
- break;
- case 10:
- printf("October: 31 days");
- break;
- case 11:
- printf("November: 30 days");
- break;
- case 12:
- printf("December: 31 days");
- break;
- default:
- printf("Invalid number");
- }
- }
- //Question 3
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- char color;
- printf("Enter color: ");
- scanf("%c", &color);
- switch (color)
- {
- case 'o':
- case 'O':
- printf("ammonia");
- case 'b':
- case 'B':
- printf("carbon monoxide");
- case 'y':
- case 'Y':
- printf("hydrogen");
- case 'g':
- case 'G':
- printf("oxygen");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement