n = input('enter a number n: '); switch n case 10 fprintf('\n It is February \n') case 12 case 3 fprintf('\n It is July \n')

EE200 Exercises‐3                                  Solution    (1) Write a MATLAB code (using switch) that will display the name of the month given a...
Author: Louise Gregory
0 downloads 1 Views 102KB Size
EE200 Exercises‐3                                  Solution   

(1) Write a MATLAB code (using switch) that will display the name of the month given an  integer number between 1 and 12 (1 for January, 2 for February, etc.). The number  should be read in from the user (using input) and the program should display the name  of the month or an error message if the number is not in the range of 1 to 12.    n = input('Enter a number n: ');  switch n   case 1   fprintf('\n It is January \n')   case 2   fprintf('\n It is February \n')   case 3   fprintf('\n It is March \n')   case 4   fprintf('\n It is April \n')   case 5   fprintf('\n It is May \n')   case 6   fprintf('\n It is June \n')   case 7   fprintf('\n It is July \n')   case 8   fprintf('\n It is August \n')   case 9   fprintf('\n It is September \n')   case 10   fprintf('\n It is October \n')   case 11   fprintf('\n It is November \n')   case 12   fprintf('\n It is December \n')   otherwise   fprintf('\n You must enter a integer between 1 and 12 \n')  end         

(2) Write a code that will display exam grade entered by the user. The grade should be read  from the user (using input) and should be an integer with 0 being the minimum grade  and 100 being the maximum grade. The program should display the letter grade. The  letter grades are assigned using the scale: A (90 – 100), B (80 – 89), C (70 – 79), D (60 –  69), and F (