Write a program that for the integers from 1 to 100, inclusive:
1) determines the sum
2) counts how many of the integers from the end of the summation it takes to reach at least half of the total sum. That is, when calculating 100 + 99 + 98 + ... + n = total_sum/2, how many integers does it take to reach n?
I have this half way done.
Output I am getting:
The sum from 1 to 100 is 5050
Half the sum is 0
How do I divide the sum by 2 to get 2525? I'm having trouble with it.Code:#include <stdio.h> int main() { int i; int sum; for( i = 1; i <= 100; i++) { sum += i; } printf("The sum from 1 to 100 is %d\n", sum); for (i = 1; i <= 100; i++) { sum /= i; } printf("Half the sum is %d\n", sum); }
Thanks for your help.