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.
- clc;
- close all;
- a=input('enter a number');
- if mod(a,2)==0 %mod refers to to modulus
- fprintf('%d is even',a);
- end
Program 9
WAP to check even or odd number.
- clc;
- close all;
- a=input('enter a number');
- if mod(a,2)==0 %mod refers to to modulus
- fprintf('%d is even',a);
- else
- fprintf('%d is not even',a);
- end
Program 10
WAP to print months of a year
- clc;
- clear all;
- close all;
- m=input('enter the month no. = ');
- switch(m)
- case 1
- fprintf('january');
- case 2
- fprintf('february');
- case 3
- fprintf('march');
- case 4
- fprintf('april');
- case 5
- fprintf('may');
- case 6
- fprintf('june');
- case 7
- fprintf('july');
- case 8
- fprintf('august');
- case 9
- fprintf('september');
- case 10
- fprintf('october');
- case 11
- fprintf('november');
- case 12
- fprintf('december');
- otherwise
- fprintf('this is not a geniune month');
- end
Program 11
WAP to print quarters of months of a year
- clc;
- clear all;
- close all;
- m=input('enter the month no. = ');
- switch(m)
- case 1
- case 2
- case 3
- fprintf('march');
- case 4
- case 5
- case 6
- fprintf('june');
- case 7
- case 8
- case 9
- fprintf('september');
- case 10
- case 11
- case 12
- fprintf('december');
- otherwise
- fprintf('this is not a geniune month');
- end
Program 12
WAP to identify vowel and consonant (type 1)
- %to recieve any string from keybord we must put in between '........'
- clc;
- close all;
- m=input('enter a word = ');
- switch(m)
- case 'a'
- fprintf('VOWEL');
- case 'e'
- fprintf('VOWEL');
- case 'i'
- fprintf('VOWEL');
- case 'o'
- fprintf('VOWEL');
- case 'u'
- fprintf('VOWEL');
- case 'A'
- fprintf('VOWEL');
- case 'E'
- fprintf('VOWEL');
- case 'I'
- fprintf('VOWEL');
- case 'O'
- fprintf('VOWEL');
- case 'U'
- fprintf('VOWEL');
- otherwise
- fprintf('CONSONANT');
- end
Program 13
WAP to identify vowel and consonant (type 2)
- clc;
- clear all;
- close all;
- m=input('enter a word = ');
- switch(m)
- case 'a'
- case 'e'
- case 'i'
- case 'o'
- case 'u'
- case 'A'
- case 'E'
- case 'I'
- case 'O'
- case 'U'
- fprintf('VOWEL');
- otherwise
- fprintf('CONSONANT');
- end
Program 14
WAP to print days of a week
- clc;
- clear all;
- close all;
- w=input('enter the week no =');
- switch(w);
- case 1
- fprintf('sunday');
- case 2
- fprintf('monday');
- case 3
- fprintf('tuesday');
- case 4
- fprintf('wednesday');
- case 5
- fprintf('thursday');
- case 6
- fprintf('friday');
- case 7
- fprintf('saturday');
- otherwise
- fprintf('error');
- end
Program 15
WAP to show the grade according to student marks
- clc;
- clear all;
- close all;
- m=input('enter the mark of a student = ');
- if(m>=80)
- fprintf('1st div',m);
- elseif(m>=60)
- fprtint('2nd div',m);
- elseif(m>=30)
- fprintf('3rd div',m);
- else
- fprintf('fail');
- end
Program 16
WAP to check equilateral triagle
- clc;
- clear all;
- close all;
- a=input('entr the value of the 1st side of the triangle = ');
- b=input('entr the value of the 2nd side of the triangle = ');
- c=input('entr the value of the 3rd side of the triangle = ');
- if((a==b)&&(b==c)&&(c==a))
- fprintf('it is an equilateral triangle');
- else
- fprintf('it is not an equilateral triangle');
- end
Program 17
WAP to check the values to create a perfect triangle
- clc;
- close all;
- a=input('entr the value of the 1st side of the triangle = ');
- b=input('entr the value of the 2nd side of the triangle = ');
- c=input('entr the value of the 3rd side of the triangle = ');
- p=sqrt((a^2)+(b^2));
- if(c==p)
- fprintf('it is a triangle');
- else
- fprintf('it is not a triangle');
- end
Program 18
WAP to check leap year
- clc;
- close all;
- y=input('enter the year = ');
- if(((mod(y,100)==0)&&(mod(y,400)==0))||(mod(y,100)~=0)&&(mod(y,4)==0)))
- fprintf('it is a leap year');
- else
- fprintf('it is not a leap year');
- end
Post a Comment
If you have any doubts regarding this topic...
feel free to ask...