Pages

Labels

C Program to calculate two number is even or odd


This program calculates whether the given two inputs sum is odd or even



#include<stdio.h>
#include<math.h>

main() {
    int a,b,sum;
    printf("Enter 1st no");
    scanf("%d",&a);
    printf("Enter 2 nd no");
    scanf("%d",&b);
    s=(a+b)%2;
    if(s==0) {
        printf("Even \n");
    } else {
        printf("Odd \n");
    }
    getch();
}


Output:--
Enter 1st no  11
Enter 2nd no  20
Odd

How it works
It asks for two inputs, then it add those two numbers and then divides the sum by 2. If its remainder is 0 then it shows output as Even  else shows Odd.

Followers