Home > Back-end >  C: calculate the even number and 1 to 100000
C: calculate the even number and 1 to 100000

Time:09-26

CodePudding user response:

Formulas are derived,,,,,,,

CodePudding user response:

#include
#include

Int main ()
{
int i=1;
int sum=0;
While (I & lt; 10000)
{
If (I % 2==0)
sum +=i;
i++;
}
Printf (" % d ", sum);
return 0;
}

CodePudding user response:

Arithmetic series summation formula
2 + 4 + 6 +... + 100000=2 * (1 + 2 + 3 +... * (50000 + 50000)=2 + 1) * 50000/2=(50000 + 1) * 50000

CodePudding user response:

For (I=2; i<=10000; I +=2)
The sum +=I;

CodePudding user response:

reference 4 floor newshou1 response:
for (I=2; i<=10000; I +=2)
The sum +=I;

This, simple, good understand ~
  • Related