Some basic programs based on loops are given below. And most of the problems will be solved like this.
If you are having some more programs please share with me. I am very much fascinated to solve them for you.
Program 19
WAP to 1 to 10 using loops
- clc;
- clear all;
- close all;
- for a=1:10
- fprintf(' %d ',a);
- end
Program 20
WAP to display factors of number
- clc;
- clear all;
- close all;
- i=16;
- while(i<=36)
- if(mod(i,4)==0)
- continue;
- end
- i=i+2;
- fprintf('%d',i);
- end
Program 21
WAP to print a multiplication table of a number
- clc;
- clear all;
- close all;
- n=input('enter an number = ');
- i=1;
- while(i<=10)
- fprintf('%d*%d = %d\n',n,i,n*i);
- i=i+1;
- end
Program 22
WAP to check prime number
- clc;
- clear all;
- close all;
- n=input('enter a number = ');
- i=2;
- while(i<=n)
- if(mod(n,i) == 0)
- break;
- end
- i=i+1;
- end
- if(i==n)
- fprintf('%d is prime no',n);
- else
- fprintf('%d is not prime no',n);
- end
Program 23
WAP to check prime numbersfrom 110 to 140
- clc;
- clear all;
- close all;
- for a= 110:140
- i=2;
- while(i<=a)
- if(mod(a,i) == 0)
- break;
- end
- i=i+1;
- end
- if(i==a)
- fprintf('%d ',a);
- end
Program 24
WAP to print the sum of digits of a number
- clc;
- clear all;
- close all;
- i=0;
- while(i<=10)
- if(i == 5)
- break;
- end
- i=i+1;
- fprintf('%d ',i);
- end
Post a Comment
If you have any doubts regarding this topic...
feel free to ask...