While loop for sums?
조회 수: 8 (최근 30일)
이전 댓글 표시
Add up the squares of all odd positive integers until it equals or exceeds 5 million.
(1^2+3^2...)
댓글 수: 2
Steven Lord
2016년 12월 1일
Show what you've tried to do to solve the problem and ask a specific question about where you're having difficulty and you may receive some guidance.
답변 (3개)
Image Analyst
2016년 12월 1일
Try this:
theSum = 0; % Initialize
thisNumber = -1;
while theSum < 5000000
thisNumber = thisNumber + .......
theSum = theSum + ......
end
I've given you a start. Please finish the rest of your homework yourself.
댓글 수: 0
s.p4m
2016년 12월 1일
편집: s.p4m
2016년 12월 2일
sum=0;
k=0;
while(sum<=5*10^6)
if(mod(k,2))
sum=sum+k^2;
end
k=k+1;
end
Next time please try to solve your homework by yourself
댓글 수: 5
s.p4m
2016년 12월 2일
Thanks for the answer. You are right with every point.
I didn't know about the rule not to do outher people homework, but I will embrace it from now on.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!