Wednesday, 1 March 2017

Even And Odd Numbers


  • Two methods available in c programing...

#include <stdio.h>
int main()
{
    int i;

    printf("Enter an integer: ");
    scanf("%d", &i);

    if(i % 2 == 0)
        printf("%d is even.", i);
    else
        printf("%d is odd.", i);

    return 0;
};


Output :















(2) Methods Condition Operator

Program :

#include <stdio.h>
int main()
{
    int A;

    printf("Enter an integer: ");
    scanf("%d", &A);

    (A % 2 == 0) ? printf("%d is even.", A) : printf("%d is odd.", A);

    return 0;
}

Output :








No comments:

Post a Comment