search
Login

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

2 votes
4k views
c  program to check whether the given number is even or odd.
asked Advisor 7.1k points 10 23 42

4 Answers

0 votes
Program:
#include <stdio.h>
int main()
{
 int a;
 printf("Enter a: \n");
 scanf("%d", &a);
 /* logic */
 if (a % 2 == 0)
{
  printf("The given number is EVEN\n");
 }
 else
 {
  printf("The given number is ODD\n");
 }
 return 0;
}

Output:
Enter a: 2
The given number is EVEN

Example 1: If entered number is an even number
          Let value of 'a' entered is 4
          if(a%2==0) then a is an even number, else odd.
   i.e.  if(4%2==0) then 4 is an even number, else odd.
To check whether 4 is even or odd, we need to calculate (4%2).
/* % (modulus) implies remainder value. */
/* Therefore if the remainder obtained when 4 is divided by 2 is 0, then 4 is even. */
     4%2==0 is true
     Thus 4 is an even number.
answered Expert 12.3k points 7 13 26
0 votes
#include<stdio.h>
void main()
{
int a;
printf("enter a value");
scanf9"%d",&a);
if(a/2==0)
printf("the given no'r is even")
else
printf(the no'r is odd");
answered Jr Member 630 points 2
0 votes

 

#include<stdio.h>
main()
{
int r,n;
printf("\nEnter a positive number : ");
scanf("%d",&n);
r =n%2;
if(r==0)
printf("\nThe %d is an even number",n);
else
printf("\nThe %d is an odd number",n);
}
answered Sr Member 1.2k points 2 5 15
0 votes

#include<stdio.h>

#include<conio.h>

void main()

{

int a;

clrscr();

printf(“enter the number\n”);

scanf(“%d”,&a);

if(a%2==0)

printf(“even number”);

else

printf(“odd number”);

getch();

}

Output:

enter the number

9

odd number

answered Guru 24.6k points 29 52 81

Related questions

0 votes
2 answers 743 views
743 views
asked Smita Advisor 7.1k points 10 23 42
0 votes
1 answer 80 views
80 views
Write a program to accept a number and check whether the number is prime or not
asked anonymous
0 votes
2 answers 5.6K views
5.6K views
Write a program to check whether the given string is a palindrome.
asked sagar Expert 12.3k points 7 13 26
0 votes
1 answer 403 views
0 votes
1 answer 1.8K views
...