Some basic programmes on Condition statement is solved below. Most problems based on the condition can be loved like this.

Program 8 
WAP to check even number.
  1. clc;
  2. close all;
  3. a=input('enter a number');
  4. if mod(a,2)==0 %mod refers to to modulus
  5.     fprintf('%d is even',a);
  6. end

Program 9
WAP to check even or odd number.

  1. clc;
  2. close all;
  3. a=input('enter a number');
  4. if mod(a,2)==0 %mod refers to to modulus
  5.     fprintf('%d is even',a);
  6. else
  7.     fprintf('%d is not even',a);
  8. end

 Program 10
WAP to print months of a year

  1. clc;
  2. clear all;
  3. close all;
  4. m=input('enter the month no. = ');
  5. switch(m)
  6.     case 1
  7.         fprintf('january');
  8.     case 2
  9.         fprintf('february');
  10.     case 3
  11.         fprintf('march');
  12.     case 4
  13.         fprintf('april');
  14.     case 5
  15.         fprintf('may');
  16.     case 6
  17.         fprintf('june');
  18.     case 7
  19.         fprintf('july');
  20.     case 8
  21.         fprintf('august');
  22.     case 9
  23.         fprintf('september');
  24.     case 10
  25.         fprintf('october');
  26.     case 11
  27.         fprintf('november');
  28.     case 12
  29.         fprintf('december');
  30.     otherwise
  31.         fprintf('this is not a geniune month');
  32. end

Program 11 

WAP to print quarters of months of a year

  1. clc;
  2. clear all;
  3. close all;
  4. m=input('enter the month no. = ');
  5. switch(m)
  6.     case 1
  7.     case 2
  8.     case 3
  9.         fprintf('march');
  10.     case 4
  11.     case 5
  12.     case 6
  13.         fprintf('june');
  14.     case 7
  15.     case 8
  16.     case 9
  17.         fprintf('september');
  18.     case 10
  19.     case 11
  20.     case 12
  21.         fprintf('december');
  22.     otherwise
  23.         fprintf('this is not a geniune month');
  24. end

Program 12
WAP to identify vowel and consonant (type 1)

  1. %to recieve any string from keybord we must put in between '........'
  2. clc;
  3. close all;
  4. m=input('enter a word = ');
  5. switch(m)
  6.     case 'a'
  7.         fprintf('VOWEL');
  8.     case 'e'
  9.         fprintf('VOWEL');
  10.     case 'i'
  11.         fprintf('VOWEL');
  12.     case 'o'
  13.         fprintf('VOWEL');
  14.     case 'u'
  15.         fprintf('VOWEL');
  16.     case 'A'
  17.         fprintf('VOWEL');
  18.     case 'E'
  19.         fprintf('VOWEL');
  20.     case 'I'
  21.         fprintf('VOWEL');
  22.     case 'O'
  23.         fprintf('VOWEL');
  24.     case 'U'
  25.         fprintf('VOWEL');
  26.     otherwise
  27.         fprintf('CONSONANT');
  28. end

Program 13
WAP to identify vowel and consonant (type 2)

  1. clc;
  2. clear all;
  3. close all;
  4. m=input('enter a word = ');
  5. switch(m)
  6.     case 'a'
  7.     case 'e'
  8.     case 'i'
  9.     case 'o'
  10.     case 'u'
  11.     case 'A'
  12.     case 'E'
  13.     case 'I'
  14.     case 'O'
  15.     case 'U'
  16.         fprintf('VOWEL');
  17.     otherwise
  18.         fprintf('CONSONANT');
  19. end

Program 14
WAP to print days of a week

  1. clc;
  2. clear all;
  3. close all;
  4. w=input('enter the week no =');
  5. switch(w);
  6.     case 1
  7.         fprintf('sunday');
  8.     case 2
  9.         fprintf('monday');
  10.     case 3
  11.         fprintf('tuesday');
  12.     case 4
  13.         fprintf('wednesday');
  14.     case 5
  15.         fprintf('thursday');
  16.     case 6
  17.         fprintf('friday');
  18.     case 7
  19.         fprintf('saturday');
  20.     otherwise
  21.         fprintf('error');
  22. end

Program 15
WAP to  show the grade according to student marks 

  1. clc;
  2. clear all;
  3. close all;
  4. m=input('enter the mark of a student = ');
  5. if(m>=80)
  6.     fprintf('1st div',m);
  7. elseif(m>=60)
  8.     fprtint('2nd div',m);
  9. elseif(m>=30)
  10.     fprintf('3rd div',m);
  11. else
  12.     fprintf('fail');
  13. end

Program 16
WAP to check equilateral triagle

  1. clc;
  2. clear all;
  3. close all;
  4. a=input('entr the value of the 1st side of the triangle = ');
  5. b=input('entr the value of the 2nd side of the triangle = ');
  6. c=input('entr the value of the 3rd side of the triangle = ');
  7. if((a==b)&&(b==c)&&(c==a))
  8.     fprintf('it is an equilateral triangle');
  9. else
  10.     fprintf('it is not an equilateral triangle');
  11. end

Program 17

WAP to check the values to create a perfect triangle

  1. clc;
  2. close all;
  3. a=input('entr the value of the 1st side of the triangle = ');
  4. b=input('entr the value of the 2nd side of the triangle = ');
  5. c=input('entr the value of the 3rd side of the triangle = ');
  6. p=sqrt((a^2)+(b^2));
  7. if(c==p)
  8.     fprintf('it is a triangle');
  9. else
  10.     fprintf('it is not a triangle');
  11. end

Program 18
WAP to check leap year

  1. clc;
  2. close all;
  3. y=input('enter the year = ');
  4. if(((mod(y,100)==0)&&(mod(y,400)==0))||(mod(y,100)~=0)&&(mod(y,4)==0)))
  5.     fprintf('it is a leap year');
  6. else
  7.     fprintf('it is not a leap year');
  8. end
contact-form

Post a Comment

If you have any doubts regarding this topic...
feel free to ask...

Previous Post Next Post