Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.31 KB | None | 0 0
  1. //Assignment 5 Structured programming
  2. //Question 1
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. int main()
  6. {
  7.     char grade;
  8.     printf("Enter grade: ");
  9.     scanf("%c", &grade);
  10.     switch(grade)
  11.     {
  12.         case 'A':
  13.         case 'a':
  14.             printf("Excellent");
  15.             break;
  16.         case 'B':
  17.         case 'b':
  18.             printf("Very good");
  19.             break;
  20.         case 'C':
  21.         case 'c':
  22.             printf("Good");
  23.             break;
  24.         case 'D':
  25.         case 'd':
  26.             printf("Poor");
  27.             break;
  28.         case 'F':
  29.         case 'f':
  30.             printf("Failed");
  31.             break;
  32.         default:
  33.             printf("Invalid");
  34.     }
  35. }
  36.  
  37. //Question 2
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. int main()
  41. {
  42.     int month;
  43.     printf("Enter number of month: ");
  44.     scanf("%d", &month);
  45.     switch (month)
  46.     {
  47.         case 1:
  48.             printf("January: 31 days");
  49.             break;
  50.         case 2:
  51.             printf("February: 28 days");
  52.             break;
  53.         case 3:
  54.             printf("March: 31 days");
  55.             break;
  56.         case 4:
  57.             printf("April: 30 days");
  58.             break;
  59.         case 5:
  60.             printf("May: 31 days");
  61.             break;
  62.         case 6:
  63.             printf("June: 30 days");
  64.             break;
  65.         case 7:
  66.             printf("July: 31 days");
  67.             break;
  68.         case 8:
  69.             printf("August: 31 days");
  70.             break;
  71.         case 9:
  72.             printf("September: 30 days");
  73.             break;
  74.         case 10:
  75.             printf("October: 31 days");
  76.             break;
  77.         case 11:
  78.             printf("November: 30 days");
  79.             break;
  80.         case 12:
  81.             printf("December: 31 days");
  82.             break;
  83.         default:
  84.             printf("Invalid number");
  85.     }
  86. }
  87.  
  88. //Question 3
  89. #include <stdio.h>
  90. #include <stdlib.h>
  91. int main()
  92. {
  93.     char color;
  94.     printf("Enter color: ");
  95.     scanf("%c", &color);
  96.     switch (color)
  97.     {
  98.         case 'o':
  99.         case 'O':
  100.             printf("ammonia");
  101.         case 'b':
  102.         case 'B':
  103.             printf("carbon monoxide");
  104.         case 'y':
  105.         case 'Y':
  106.             printf("hydrogen");
  107.         case 'g':
  108.         case 'G':
  109.             printf("oxygen");
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement