Find the number is odd or even using c language?

their is one basic logic apply in this program that is if number is divisible by 2 then then number is even other wise number is odd.

for that we use if else block and syntex of if else is :

in if block we should put condition (n%2 == 0) and if condition use then our if block execute other wise else block is execute

 '%' (Modulo operator) give remender of division. modulo operator is part of arithmetic operator.

'==' check for equality

if (/* condition */)
{
    /* code */
}
else
{
    /* code */
}


 



now implement every thing we discuss above and write our program for finding odd and even number. show below source code for better understanding.


SOURCE CODE:

#include<stdio.h>
int main()
{
int a;
printf("enter any number to find out the number is odd or even\n");
scanf("%d"&a);
if(a %2==0){
    printf("%d is even number",a);
}
else{
    printf("%d is odd number",a);
}
return 0;
}


OUTPUT:



0 Comments