#include <stdio.h>
int main() {
// Declare the variable
int sum;
for(int i=1;i<=100;i=i+1) {
// Check if i is an odd number
if(i%2 == 1) {
sum = sum + i*i*i;
}
// Print the sum
printf("%d", sum);
return 0;
Declare sum as an integer.
Use a for loop, which runs from 1 to 100 and increments by 1 each time.
Use an if statement to check if the remainder is 1 to see if the number is odd.
Print the sum.
Return an integer value.
Answer:
int sum = 0;
for (int i = 1; i < 100; i += 2) {
sum += i * i;
printf("The sum of cubes is %d", sum);
/* Prints: The sum of cubes is 166650 */
Step-by-step explanation:
If 1 should be excluded, let the for loop start at 3.
3.4m questions
4.3m answers