Write c program to sum up all divisible of 4 from 1-1000 inclusive except 40 and 200 ?

Answers

Anonymous

#include<stdio.h> int main() { int n, sum = 0; for(n = 1; n <= 1000; n++) { if(n%4!=0 || n == 40 || n == 200) continue; sum=sum+n; } printf("The sum is %d",sum); return 0; }

Quentin

int main(void) { int sum = 0; for(int i=1; i<=1000; ++i) if(i%4==0 && i!=40 && i!=200) sum += i; printf("%d", sum); return 0; }

Andy T

Oh Quentin got it right but he forgot it suppose to be C not C++, C is very archaic and with old restrictions. In this case "for (int..." can't go as C code but it is perfectly valid C++ code, it had to be "int i; for (i=1..." else it is about right on.

Chris

printf("%d", (250 * 251 / 2) * 4 - 240);

Anonymous

What is c program