Professional Documents
Culture Documents
X (1 - 1 2 3) Max X (1) Min X (1) For I 1:length (X) If X (I) Max Max X (I) End End Disp (Max) Disp (Min)
X (1 - 1 2 3) Max X (1) Min X (1) For I 1:length (X) If X (I) Max Max X (I) End End Disp (Max) Disp (Min)
X (1 - 1 2 3) Max X (1) Min X (1) For I 1:length (X) If X (I) Max Max X (I) End End Disp (Max) Disp (Min)
x=[ 1 -1 2 3];
max=x(1);
min=x(1);
for i=1:length(x)
min=x(i);
end
max=x(i);
end
end
disp(max)
disp(min)
2- Write a Matlab program that have two input integers x and y. It will
output the absolute difference of the two integers.
x=input(‘enter x’);
y=input(enter y’);
Result=0;
if x<y
Result = y-x;
elseif x>y
Result = x-y;
else
Result=0;
end
disp(Result)
3-Determine and print the number of zeros in matrix x
x=[0 1 -1 0 2 0 3];
count = 0;
if x(i)==0
count=count+1;
end
end
disp(count);
x=[ 1 -1 2 3];
for i=1:length(x)
if x(i)<0
end
end
5-Print a sequence of asterisk characters in the following configuration
**
***
****
*****
******
*******
********
for i=1: 8
for j=1:i
fprintf ('*');
end
fprintf ('\n');
end
6- Using a while loop to ask the user to input a number
between 1 and 10
disp('Incorrect input.\n');
end
disp('Correct')
7- Write a script file that asks the User to enter his Math. Exam result and
then display his grad according to the following scheme:
if d >= 85
disp(‘Excellent’);
elseif d >= 75
disp(‘V.Good’);
elseif d >= 65
disp(‘Good’);
elseif d >= 50
disp(‘Pass’);
else
disp(‘Fail);
end
8- Write a script file with a for loop that will iterate from 0 to 20. For each
iteration, it will check if the current number is even or odd, and report
that to the screen (e.g. "2 is even").
for i=0:20
if rem(i,2)==0
else
end