Jump to content

[C++]Suma patratelor perfecte pana la un numar n


AIM Katzuno Valoare
 Share

Recommended Posts

#include <iostream>
using namespace std;
//Nivel: Incepator
int main()
{
//Suma patratelor perfecte pana la n
int s=0, i, n;
cout << "Pana la cat doriti generarea?: ";
cin >> n;
for (i = 1; i <= n; i++) {
if (i*i <= n) 
s = s + i*i;
}
cout << "Suma este: " << s << endl;
 
return 0;
}

Daca aveti nelamuriri sau aveti nevoie de explicatii puteti lasa un reply la acest topic.

Edited by pH Katzuno
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.