Sum of first 100 integers?
46 次查看(过去 30 天)
显示 更早的评论
Write a script that uses a for loop to calculate the sum of the first 100 integer numbers
0 个评论
采纳的回答
更多回答(4 个)
Roger Stafford
2014-2-3
编辑:Roger Stafford
2014-2-3
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
2 个评论
Mayur Gaikwad
2017-12-7
Could someone write the script for matlab mobile version for the sum of the squares of first 100 natural numbers.. !
1 个评论
Jan
2017-12-7
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!