#include <stdio.h>
// prototype
int siguma_for(int n);
int siguma_while(int n);
int siguma_do(int n);
int siguma_rec(int n);
int siguma_for(int n)
{
int r = 0;
for (int i = 1; i <= n; ++i)
r += i;
return r;
}
int siguma_while(int n)
{
int r = 0;
while (n)
r += n--;
return r;
}
int siguma_do(int n)
{
int r = 0;
do r += n;
while (--n);
return r;
}
int siguma_rec(int n)
{
return n ? n + siguma_rec(n - 1) : 0;
}
int main(void)
{
int n = 10;
siguma_for(n),
siguma_while(n),
siguma_do(n),
siguma_rec(n) );
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+Ci8vIHByb3RvdHlwZQppbnQgc2lndW1hX2ZvcihpbnQgbik7CmludCBzaWd1bWFfd2hpbGUoaW50IG4pOwppbnQgc2lndW1hX2RvKGludCBuKTsKaW50IHNpZ3VtYV9yZWMoaW50IG4pOwoKaW50IHNpZ3VtYV9mb3IoaW50IG4pCnsKICAgIGludCByID0gMDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkKICAgICAgICByICs9IGk7CiAgICByZXR1cm4gcjsKfQoKaW50IHNpZ3VtYV93aGlsZShpbnQgbikKewogICAgaW50IHIgPSAwOwogICAgd2hpbGUgKG4pCiAgICAgICAgciArPSBuLS07CiAgICByZXR1cm4gcjsKfQoKaW50IHNpZ3VtYV9kbyhpbnQgbikKewogICAgaW50IHIgPSAwOwogICAgZG8gciArPSBuOwogICAgd2hpbGUgKC0tbik7CiAgICByZXR1cm4gcjsKfQoKaW50IHNpZ3VtYV9yZWMoaW50IG4pCnsKICAgIHJldHVybiBuID8gbiArIHNpZ3VtYV9yZWMobiAtIDEpIDogMDsKfQoKaW50IG1haW4odm9pZCkKewogICAgaW50IG4gPSAxMDsKICAgIHByaW50ZigiJWQgJWQgJWQgJWRcbiIsCiAgICAgICAgICAgc2lndW1hX2ZvcihuKSwKICAgICAgICAgICBzaWd1bWFfd2hpbGUobiksCiAgICAgICAgICAgc2lndW1hX2RvKG4pLAogICAgICAgICAgIHNpZ3VtYV9yZWMobikgKTsKICAgIHJldHVybiAwOwp9Cg==