Table of Contents
In this post, we will see how to write C Program to print even numbers from 1 to 100.
This post will address below to queries:
- C Program to print even numbers from 1 to 100
- C Program to print even numbers from 1 to n
C program to print even 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 even 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 0, then it is even number */ if(i%2 == 0) { /* counter is even, print it */ printf("%d ", i); } } return 0; } |
Output:
Printing even numbers between 1 to 100
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
C program to print even 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 even 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 0, then it is even number */ if(i%2 == 1) { /* counter is even, print it */ printf("%d ", i); } i++; } return 0; } |
Output:
Printing even numbers between 1 to 100
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
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.