This question has already been answered:

S = 1 + 2 ^ 2 + 3 ^ 3 + ... + N ^ N

Model the arithmetic cycle with the for loop operator. The exponentiation formula is not used.

Reported as a duplicate by Harry c ++ Mar 20 '17 at 7:54 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • It seems to me that if this question were closed, it would be better. - Costantino Rupert

2 answers 2

Here, try:

int N=20,S=0, P=1; for(int i=1;i<=N;i++){ P=1; for(int j=1;j<i;j++){ P = P*i; } S = S+P; } 
  • five
    @mctrane the more we answer this kind of do-it-yourself questions, the HeshCode becomes an increasingly less professional resource. - VioLet
  • But the task is simple - iproger
  • check: N = 2 S = 7, N = 3 S = 12, N = 4 S = 76 is incorrect. I understand that with the introduction of the value of N should be obtained: N = 2 S = 4, N = 3 S = 27, N = 4 S = 256. - Devil7
  • 3
    @mctrane well, look - you answered the @Devil question. He, thinking, “wow, I found a site where problems are solved quickly and freely!”, Leads a crowd of his classmates / classmates \ etc here, with equally trivial questions and, almost certainly, who cannot even ask these same questions. Is it really necessary? - VioLet 4:21 pm
  • 2
    VioLet, well, I will no longer be convinced) - iproger

Do not try to try the above!

 const int N = 20; long int S = 1; for(int i = 2; i <= N; i++) { long int P = 1; for(int j = 1; i <= j; j++) { P *= i; } S += P; } 
  • It does not differ from my code at all, except that the types of variables have changed - iproger
  • Now, almost (!) Is no different, but before that, what a crap wrote! P = P * j * j (??). And now the code is written with errors, so it will not work. "You do something bad, you do it well. Bad something - the very result" Quote. - BuilderC
  • I just thought out ... And every minute I edited the code. What kind of mistakes are there? - iproger
  • Run, find out. - BuilderC