Use Matlab Please!!! Write a program that generates three random rational number
ID: 3835857 • Letter: U
Question
Use Matlab Please!!!
Write a program that generates three random rational numbers between -10 and 10. Label the numbers A, B, and C. Display all three numbers using disp([A B C]). Then
If A is greater than B, switch the two numbers (the value of A now is stored in B and the value of B now is stored in A). Display all three numbers again.
If B is the largest number, set it to zero. Otherwise, set it equal to 100. Display all three numbers again.
If C is a negative number, set it equal to zero. Display all three numbers.
Explanation / Answer
main.m
clc
clear
a = -10;
b = 10;
r1 = a+(b-a)*rand(1,1);
A=rats(r1);
r2 = a+(b-a)*rand(1,1);
B=rats(r2);
r3 = a+(b-a)*rand(1,1);
C=rats(r3);
disp([A B C])
if A>B
R=A;
A=B;
B=R;
disp(A)
disp(B)
disp(C)
end
if r2>r1 && r2>r3
B=0;
else
B=100;
disp(A)
disp(B)
disp(C)
end
if C<0
C=0;
disp(A)
disp(B)
disp(C)
end
Output :-
2679/293 -401/1371 4282/713
2679/293
100
4282/713
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.