logical operators with while loop

조회 수: 23 (최근 30일)
anand jangid
anand jangid 2020년 12월 15일
편집: Matt Gaidica 2020년 12월 15일
%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

채택된 답변

Matt Gaidica
Matt Gaidica 2020년 12월 15일
편집: Matt Gaidica 2020년 12월 15일
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
  댓글 수: 1
anand jangid
anand jangid 2020년 12월 15일
thanks man.Now it is working.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

David Hill
David Hill 2020년 12월 15일
a=7397;
while ~(mod(a,13)==0&&mod(a,2)==0)
a=a+1;
end

KSSV
KSSV 2020년 12월 15일
x = 2 ;
while ~(mod(x,13) == 0 && sqrt(x)>=86)
x = x+2 ;
end
fprintf('The required number is %d\n',x);
The required number is 7410

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by