C Program to Check if a given Integer is Odd or Even


1. Simple C Programs


The following section gives a collection of Simple C Programs which are categorized into various Categories like Programs on Integers, Programs on Number Conversion, Programs on Recursion, Programs on Special Numbers, Programs illustrating the functions of a Computer, Programs on day-to-day activities, Programs on Unions, Programs to display Special Patterns, Programs to illustrate Call By Value and Call by Reference and Programs to illustrate the use of Arguments. The link below contains Programs for all the categories mentioned above.



 C Examples on Integers

C Programmming Language is been widely used in the field of Basic as well as Advanced Mathematics. The following section provides a list of C programs which deals with an aspect of Basic Mathematics “Integers”. The given set of Programs depict if the given Integer is odd or even, positive or negative, tests for their equality and divisibility, finds the sum of odd and even integers, swaps the values of integers and computes the sum of digits of the given integer. The programs also calculate the sum of digits in a given integer and calculates the sum of odd and even numbers.

C Program to Check if a given Integer is Odd or Even

This C Program checks if a given integer is odd or even. Here if a given number is divisible by 2 with the remainder 0 then the number is even number. If the number is not divisible by 2 then that number will be odd number.
Here is source code of the C program which checks a given integer is odd or even. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
  1. /*
  2.  * C program to check whether a given integer is odd or even
  3.  */
  4. #include <stdio.h>
  5.  
  6. void main()
  7. {
  8.     int ival, remainder;
  9.  
  10.     printf("Enter an integer : ");
  11.     scanf("%d", &ival);
  12.     remainder = ival % 2;
  13.     if (remainder == 0)
  14.         printf("%d is an even integer\n", ival);
  15.     else
  16.         printf("%d is an odd integer\n", ival);
  17. }
$ cc pgm4.c
$ a.out
Enter an integer : 100
100 is an even integer
 
$ a.out
Enter an integer : 105
105 is an odd integer






No comments:

hia friends you are seeing my blogger thank's. Powered by Blogger.