12/02/2019

C-programmed code to check even or odd number

C-programmed code to check even or odd number:

We are going to check a number is even or odd in C-programming. Here you can use any C-programming software to do it. At first we give the code of this programming and then we explain it smoothly. We always try to make easy for the beginners.



The code for check a number whether it is even or odd at below:


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


Here the output of this program below:



EXPLANATION


  •  First of all we used two packages <stdio.h> and <conio.h>. to know the uses of <stdio.h> and <conio.h> visit our packages page.
  •  we used "void main()" here you can use only "main()" if you use windows operator system or you can use "int main()" if you use Linux opareting system.know more in important syntax of our page.
  •  Here we used two integer variable 'a' and 'b'. we used 'a' for store the output number. and 'b' is used to evaluate the remainder of 'a' dividing by 2.
  •  After we used "if-else" condition. That means if 'b'=0 then the remainder is 0 so 'a' is divisible by 2 and if 'b' not equal to 0 then it will be odd number.
  •  Now we use "getch()". To know more go to "important syntax"


No comments:

Post a Comment