Saturday, 7 July 2012

c program to find odd or even(if,else)

For beginners
{I am going write the c program but before you need a c compiler(software).there are a lot of compilers(software). like Code::Blocks, dev c++  Download dev c++ its free and install it in your computer.open  dev c++ go to file-->new-->source file.}



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

#include<stdio.h>
#include<conio.h>
main()
{
      int a;
      printf("enter a number\n");
      scanf("%d",&a);
      if((a/2)*2==a)
      printf("the number %d is even",a);
      else
      printf("the number %d is odd",a);
      getch();
      }


For beginners
{After typing this program go to execute-->compile & run-->a window will pop-up-->give file name:(anything u like)-->save as type: c source files-->click save.}

IS IT HELPFIL? comment.

3 comments:

  1. if((a/2)*2==a) ......what is the logic

    ReplyDelete
  2. C program to check odd or even

    In general Even numbers are those which are divisible by 2, and which numbers are not divisible 2 is called odd numbers.
    We can easily write even odd program in c programming.

    ReplyDelete
  3. 7 easy ways to find whether a number id odd/even.
    http://www.waytosmart.com/tutorials/c-programming/c-program-to-check-odd-or-even-number-easy-ways.php

    ReplyDelete