logical operators with while loop
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
anand jangid
am 15 Dez. 2020
Bearbeitet: Matt Gaidica
am 15 Dez. 2020
%Find the smallest even integer that is
% divisible by 13 and whose
% square root is greater than 86
clc;
clear;
x=15;
a=rem(x,26);
b=sqrt(x);
while a==0 && b>86
if a==0 && b>86
fprintf('The required number is %d\n',x);
break
else
x=x+1;
end
end
0 Kommentare
Akzeptierte Antwort
Matt Gaidica
am 15 Dez. 2020
Bearbeitet: Matt Gaidica
am 15 Dez. 2020
At the risk of doing someones homework :P
clc;
clear;
x = 0; % or start at x = 86^2;
while true
a = rem(x,13);
b = sqrt(x);
if a==0 && b>86
fprintf('The required number is %d\n',x);
break;
else
x=x+2;
end
end
Weitere Antworten (2)
KSSV
am 15 Dez. 2020
x = 2 ;
while ~(mod(x,13) == 0 && sqrt(x)>=86)
x = x+2 ;
end
fprintf('The required number is %d\n',x);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!