Computer Science, asked by Sayani07, 1 year ago

write a program to find the sum of 100 odd numbers using fir loop​

Answers

Answered by LEGEND200
0

Answer:

#include <stdio.h>

int main() {

int counter;

printf("Odd numbers between 1 to 100\n");

/*

* Initialize counter with 1, and increment it in every iteration.

* For every value of counter check whether it is odd number or

* not and print it accordingly

*/

for(counter = 1; counter <= 100; counter++) {

/* Odd numbers are not divisible by 2. When an Odd

number is divided by 2, it leaves 1 as remainder */

if(counter%2 == 1) {

/* counter is odd, print it */

printf("%d ", counter);

}

}

return 0;

}

</stdio.h>

Explanation:

Output

Odd numbers between 1 to 100

1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99

Answered by acsahjosemon40
1

Answer:

#include <stdio.h>

int main() {

int counter;

printf("Odd numbers between 1 to 100\n");

/*

* Initialize counter with 1, and increment it in every iteration.

* For every value of counter check whether it is odd number or

* not and print it accordingly

*/

for(counter = 1; counter <= 100; counter++) {

/* Odd numbers are not divisible by 2. When an Odd

number is divided by 2, it leaves 1 as remainder */

if(counter%2 == 1) {

/* counter is odd, print it */

printf("%d ", counter);

}

}

return 0;

}

</stdio.h>

Explanation:

Output

Odd numbers between 1 to 100

1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99

Similar questions