having trouble with for loops
이전 댓글 표시
Having Trouble...
'Sum of N^2 with N = 1 to 1,000 using a for loop'
채택된 답변
추가 답변 (2개)
Roger Stafford
2014년 2월 13일
Here's a way to check your answer:
n = 1000;
s = n*(n+1)*(2*n+1)/6;
This gives you the same value as
s = sum((1:n).^2);
Alonso Mukendi Kalonji
2022년 10월 29일
0 개 추천
a = 1;
n= 1000;
for i = 1: n
a = a+i^2
end
disp(a)
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!