URI Online Judge Solution 1159 Sum of Consecutive Even Numbers Using C, Python Programming Language.
The program must read an integer X indefinite times (stop when X=0). For each X, print the sum of five consecutive even numbers from X, including it if X is even. If the input number is 4, for example, the output must be 40, that is the result of the operation: 4+6+8+10+12. If the input number is 11, for example, the output must be 80, that is the result of 12+14+16+18+20.
The program must read an integer X indefinite times (stop when X=0). For each X, print the sum of five consecutive even numbers from X, including it if X is even. If the input number is 4, for example, the output must be 40, that is the result of the operation: 4+6+8+10+12. If the input number is 11, for example, the output must be 80, that is the result of 12+14+16+18+20.
Input
The input file contains many integer numbers. The last one is zero.
The input file contains many integer numbers. The last one is zero.
Output
Print the output according to the example below.
Print the output according to the example below.
Input Sample | Output Sample |
4 | 40 |
URI 1159 Solution in C:
#include <stdio.h>
int main() {
while(1)
{
int n,i,j=5,s=0;
scanf("%d",&n);
if(n==0)
break;
else
{
while(j>0)
{
if(n%2 == 0)
{
s += n;
n++;
j--;
}
else
{
n++;
}
}
}
printf("%d\n",s);
}
return 0;
}
Comments
Post a Comment