Sum of first 100 integers?
Show older comments
Write a script that uses a for loop to calculate the sum of the first 100 integer numbers
Accepted Answer
More Answers (4)
Sean de Wolski
on 3 Feb 2014
for ii = 100
s = sum(1:ii);
end
Roger Stafford
on 3 Feb 2014
Edited: Roger Stafford
on 3 Feb 2014
Or you could emulate the mathematical genius, Karl Friedrich Gauss, who is said to have done it this way at the age of ten:
s = (100+1)+(99+2)+(98+3)+...+(51+50) = 50*101 = 5050
Mayur Gaikwad
on 7 Dec 2017
0 votes
Could someone write the script for matlab mobile version for the sum of the squares of first 100 natural numbers.. !
1 Comment
Jan
on 7 Dec 2017
Yes. Simply add a "^2" in Mischa's answer.
Please do not inject a new question as an answer to an existing thread. Such thread-hijacking confuses the readers, because it is not clear anymore, to which question an answer belongs.
Because this sounds like a homework, let me encourage you to try to solve this by your own.
Bhanuprasad Akula
on 3 Mar 2021
0 votes
sum(1:100)
1 Comment
Jan
on 15 Mar 2022
"uses a for loop"...
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!