336,008 views
25 votes
25 votes
Using the framework below add code to allow the loop to sum the odd numbers from 1 to 10 in the loop and print the sum out at the end. Recall that you can use modulo to determine if a number is odd or even. Your sum should make use of the loop counter or your own loop counting variable. So on the first loop if that integer number is an odd number, it should be added to the running total or sum variable. This should be done inside the for loop. Note that the loop counter starts at 1 instead of 0 in this case.

Your output should equal: 25 for this loop.


#include
< stdio.h >


int main(void)

{

int sum = 0;

for(int i = 1; i <=10; i++)

{

/* Your solution here */


}

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

return 0;

}//end main

User Danizmax
by
2.9k points

1 Answer

12 votes
12 votes

Answer:

Below

Step-by-step explanation:

#include <stdio.h>

int main(void){

int sum = 0;

for(int i = 1; i <=10; i++){

if (i % 2 != 0 ){

sum += i;

}

}

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

return 0;

}//end main

User Taisha
by
3.2k points