C program to check whether the given number is even or odd | My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Tuesday, June 25, 2019

C program to check whether the given number is even or odd | My CS Tutorial


In this tutorial, we will learn how to write a program to check the given number is even or odd.We write a program by using if else statement that find the given number is even or odd.


Solution:



  • In this program we will use two header files.
  • In this program we will use one variable a.
  • We declared this variable a in int data type.
  • Then we will enter the value of a.
  • We will use if else statement with one conditions which is (a%2==0).
  • And after it we will print the statement or body.
  • When we use these statement the condition execute own statement.
  • If the condition is false the else statement will be executed.



C program code


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


Output 1:






Output 2:





We will write a program by using if else statement that find the given number is even or odd.we will use one variable a and declared it in into data type.
      Then we will use if else statement for use condition. And find the even or odd number.

In the first compiler will check the if condition. If the condition is true then the statement of if will be executed otherwise else statement will be executed.


I hope that you understand everything easily.If you have any problem or question so you write a comment and follow me on this blog and my Facebook page and on Instagram.Share the post.




No comments:

Post a Comment