Ad Code

Responsive Advertisement

1159 - Sum of Consecutive Even Numbers

Author: Ismail Hosen

Daffodil International University





Problem Link

//Please follow from main function

#include<stdio.h>

int main(){

  int j, k, sum, x;

    while(1){

        scanf("%d", &x);

        if(x==0){

          break;

        }else{

          sum=0, k=1;

          for(j=x; k<=5; j++){

            if(j%2==0){

              k++;

              sum+=j;

            }

          }

          printf("%d\n", sum);

        }

    }

  return 0;

}




Post a Comment

0 Comments