instance of java

RSS Feed URL: http://instanceofjavaforus.blogspot.in/
Category: Java | Total Views: 1263

Latest entries from this feed

C program for even or odd using for loop

Posted on 14 May 2017 | 10:29 am by InstanceOfJava

  • 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
















Related products