Q:

C program to check numbers are EVEN or ODD from 1 to N.

0

C program to check numbers are EVEN or ODD from 1 to N.

This program will read value of N and print all numbers from 1 to N with EVEN and ODD after checking the numbers whether they are EVEN or ODD.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Print number from 1 to N with EVEN and ODD message using C program

/*C program to check numbers are EVEN or ODD from 1 to N.*/

#include <stdio.h>

int checkEven(int num)
{
    /*if number (num) is divisible by 2, number is even*/
    if (num % 2 == 0)
        return 1;
    else
        return 0;
}

int main()
{
    int i, n;

    printf("Enter the value of N: ");
    scanf("%d", &n);

    for (i = 1; i <= n; i++) {
        if (checkEven(i))
            printf("%4d [EVEN]\t", i);
        else
            printf("%4d [ODD]\t", i);
    }

    return 0;
}

Output:

Enter the value of N: 100

    1 [ODD]         2 [EVEN]        3 [ODD]         4 [EVEN]        5 [ODD]
    6 [EVEN]        7 [ODD]         8 [EVEN]        9 [ODD]        10 [EVEN]
11 [ODD]        12 [EVEN]       13 [ODD]        14 [EVEN]       15 [ODD]
16 [EVEN]       17 [ODD]        18 [EVEN]       19 [ODD]        20 [EVEN]
21 [ODD]        22 [EVEN]       23 [ODD]        24 [EVEN]       25 [ODD]
26 [EVEN]       27 [ODD]        28 [EVEN]       29 [ODD]        30 [EVEN]
31 [ODD]        32 [EVEN]       33 [ODD]        34 [EVEN]       35 [ODD]
36 [EVEN]       37 [ODD]        38 [EVEN]       39 [ODD]        40 [EVEN]
41 [ODD]        42 [EVEN]       43 [ODD]        44 [EVEN]       45 [ODD]
46 [EVEN]       47 [ODD]        48 [EVEN]       49 [ODD]        50 [EVEN]
51 [ODD]        52 [EVEN]       53 [ODD]        54 [EVEN]       55 [ODD]
56 [EVEN]       57 [ODD]        58 [EVEN]       59 [ODD]        60 [EVEN]
61 [ODD]        62 [EVEN]       63 [ODD]        64 [EVEN]       65 [ODD]
66 [EVEN]       67 [ODD]        68 [EVEN]       69 [ODD]        70 [EVEN]
71 [ODD]        72 [EVEN]       73 [ODD]        74 [EVEN]       75 [ODD]
76 [EVEN]       77 [ODD]        78 [EVEN]       79 [ODD]        80 [EVEN]
81 [ODD]        82 [EVEN]       83 [ODD]        84 [EVEN]       85 [ODD]
86 [EVEN]       87 [ODD]        88 [EVEN]       89 [ODD]        90 [EVEN]
91 [ODD]        92 [EVEN]       93 [ODD]        94 [EVEN]       95 [ODD]
96 [EVEN]       97 [ODD]        98 [EVEN]       99 [ODD]       100 [EVEN]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C program to print all Armstrong Numbers from 1 to... >>
<< C program to print all prime numbers from 1 to N....