C Program To Print Even Numbers From 1 To 100

In this post, we will learn how to print even numbers from 1 to 100 using C Programming language.

C Program To Print Even Numbers From 1 To 100

Even Numbers are those numbers that can be divided into two equal groups or pairs and are exactly divisible by 2. For example: 2, 4, 6, 8, 10 and so on.

We will be checking whether the number is exactly divisible by 2 or not, if yes then that number is an even number. And we will print that number.

Similarly, we will be printing all the even numbers lying in a given range.

So, without further ado, let’s begin the tutorial.

C Program To Print Even Numbers From 1 To 100

// C Program To Print Even Numbers From 1 To 100
#include <stdio.h>
int main(){
    for (int i = 2; i <= 100; i++){
        if (i % 2 == 0){
            printf("%d\n", i);
        }
    }
    return 0;
}

Output

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

How Does This Program Work ?

    for (int i = 2; i <= 100; i++){
        if (i % 2 == 0){
            printf("%d\n", i);
        }
    }

In this program, we have a loop statement from 1 to 100 which checks for every value of i.

If i % 2 == 0 is true, then that value of i is an even number and we will print it .

This process continues until i <= 100.

C Program To Print Even Numbers From 1 TO N

// C Program To Print Even Numbers from 1 To N Using Loop
#include <stdio.h>
int main(){
    int i, num;
    
    // Asking for Input
    printf("Enter The Maximum Value: ");
    scanf("%d", &num);
    
    for (i = 1; i <= num; i++){
        if (i % 2 == 0){
            printf("%d \n", i);
        }
    }
    return 0;
}

Output

Enter The Maximum Value: 25
2 
4 
6 
8 
10 
12 
14 
16 
18 
20 
22 
24 

C Program To Display Even Numbers in a Given Range

// C Program To Display Even Numbers in a Given Range
#include <stdio.h>
int main(){
    int i, min, max;
    
    // Asking for Input
    printf("Enter the Minimum Value: ");
    scanf("%d", &min);
    printf("Enter the Maximum Value: ");
    scanf("%d", &max);
    
    if (min % 2 != 0){
        min++;
    }
    printf("Even Numbers Between %d and %d are:", min, max);
    for (i = min; i <= max; i = i + 2){
        printf("%d\n", i);
    }
    return 0;
}

Output

Enter the Minimum Value: 5
Enter the Maximum Value: 25
Even Numbers Between 6 and 25 are:6
8
10
12
14
16
18
20
22
24

C Program To Print Even Numbers from 1 To N Without Using If Statement

// C Program To Display Even Numbers from 1 To N Without Using If Statement
#include <stdio.h>
int main(){
    int i, num;
    
    // Asking for Input
    printf("Enter the Maximum Value: ");
    scanf("%d", &num);
    
    printf("Even Numbers Between 1 to %d are:\n", num);
    for (i = 2; i <= num; i = i + 2){
        printf("%d\n", i);
    }
    return 0;
}

Output

Enter the Maximum Value: 30
Even Numbers Between 1 to 30 are:
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30

Conclusion

I hope after going through this post, you understand how to print even numbers from 1 to 100 using C Programming language.

If you have any doubt regarding the problem, feel free to contact us in the comment section. We will be delighted to help you.

Also Read:

Leave a Comment

Your email address will not be published.