• If a number is divisible by 2 then it is an even number.
  • If a number is not divisible by to it is an odd number.
  • To check even or odd number in c we just need to check that using one if condition.
  • If if condition of number%2 returns true then it is even number other wise it is odd number.
  • Let us see an example c program to check a given number is even or odd without using any recursive function.



Program #1: write a c program to check a number is even or odd without using recursive function.


  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6.   
  7.   int number;
  8.  
  9.     printf("Enter a nuber to check even or odd");
  10.     scanf("%d", &number);
  11.  
  12.     // returns true if number is divisible by 2: even
  13.     if(number % 2 == 0)
  14.         printf("%d is even.", number);
  15.     else
  16.         printf("%d is odd.", number);
  17.  
  18. getch();
  19.  
  20. }

   Output:


evenorodd in c without function



Program #2: write a c program to check a number is even or odd without using if condition














Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu