Contact Learn C
Copy Program Share Program

Program 5:To print whether given number is Odd or Even

Program 5:

int i;

printf("Enter a Number to know whether it is even or odd\n");
printf("The number %d is Even",i);

printf("The number %d is Odd",i);
  1. Here we declared an integer 'i'.
  2. Then we took the input from user using scanf statement.
  3. As we know modulus operator is used to return the reminder of two values as(10%3=1, 12%2=0).
  4. So if you do modulus with 2 then the reminder would be 'zero' for Even numbers and '1' for Odd numbers.
  5. If we divide 'i' with '2' using mod operator then depending upon condition the respective 'printf' will be executed.

Print whether given number is Odd or Even


No comments:

Post a Comment

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide