having trouble with for loops
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Joseph
le 13 Fév 2014
Réponse apportée : Alonso Mukendi Kalonji
le 29 Oct 2022
Having Trouble...
'Sum of N^2 with N = 1 to 1,000 using a for loop'
0 commentaires
Réponse acceptée
Plus de réponses (2)
Roger Stafford
le 13 Fév 2014
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);
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!