Table of Contents
In this post, we will see how to write C Program to print odd numbers from 1 to 100.
This post will address below to queries:
- C Program to print odd numbers from 1 to 100
- C Program to print odd numbers from 1 to n
C program to print odd numbers from 1 to 100 using for loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <stdio.h> int main() { int i; printf("Printing Odd numbers between 1 to 100\n"); /* Start for loop from 1 to 100 */ for(i = 1; i <= 100; i++) { /* Check remainder when divided by 2 If remainder is 1, then it is odd number */ if(i%2 == 1) { /* counter is odd, print it */ printf("%d ", i); } } return 0; } |
Output:
Printing 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
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
C program to print odd numbers from 1 to 100 using while loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include <stdio.h> int main() { int i=1; printf("Printing Odd numbers between 1 to 100\n"); /* Start while loop from 1 to 100 */ while(i <= 100) { /* Check remainder when divided by 2 If remainder is 1, then it is odd number */ if(i%2 == 1) { /* counter is odd, print it */ printf("%d ", i); } i++; } return 0; } |
Output:
Printing 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
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
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.