38+51 = 89
Chat with our AI personalities
int sum = 0; for (int i = 51; i < 200; i = i + 2){ sum += i; } return sum;
I can't imagine a useful reason to have a recursive function to find this, but here you go: int sumEvens(int start, int end) { // end condition if (start > end) { return 0; } // correction if we start on an odd number if (start % 2 == 1) { return sumEvens(start + 1, end); } // actual work return start + sumEvens(start + 2, end); } Invoke with sumEvens(2, 50) to get the sum of all even numbers in the range [2,50]
Sum = Sum + first number Sum = Sum + second number Sum = Sum + third number Average = 1/3 x Sum
to print the sum of first ten numbers:- void main() {int i,sum; sum=0; while(i<=10) sum=sum+i; i=i+1; } printf("The sum is : %d",sum); }
The following will sum all integers from 1-100. Adjust according to your needs.int sum = 0;for (int i = 1; i