how to code this

x=input
y=input
with using if and for
-summation of numbers beetwen x and y
-average of numbers beetwen x and y
-finding how many numbers there are in beetwen x and y
-generate 5 random numbers beetwen x and y
with using if and while
-summation of numbers beetwen x and y
-average of numbers beetwen x and y
-finding how many numbers there are in beetwen x and y
can you help me with this quiz (matlab)

3 个评论

For input read about input. For loops read about for. For mean read about mean.
with using if and for
% Assumption that x and y are integers and y>x
%summation of numbers beetwen x and y
sum= 0
for i=x:1:y
sum = sum +i;
end
%average of numbers beetwen x and y
avg = sum/(y-x+1);
%finding how many numbers there are in beetwen x and y
numbers = y-x+1;
%generate 5 random numbers beetwen x and y
% Assuming the difference is greater than 5
randnum = ranperm(y-x) +x;
Similarly can be done for while
thank you ! , as a beginner i would be grateful if you can help me with while too

回答(1 个)

Guru Kumaresan
Guru Kumaresan 2021-7-13

0 个投票

Hi Sinan,
It seems you are new to MATLAB programming. To start with programming in MATLAB you can start with MATLAB Onramp course – MATLAB Onramp
After completing it, to get some more knowledge on MATLAB you can go for a course for MATLAB fundamentals - MATLAB fundamentals

此问题已关闭。

产品

版本

R2016a

标签

尚未输入任何标签。

关闭:

2021-8-20

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by