Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Tuesday, July 21, 2020

C program to check number is even or odd

C program to check given number is even or odd 

Write a C program to input any number from user and check whether the given number is even or odd using if...else. Let's see the below step by step logic check whether the given number is even or odd using if...else. 

C program to check even or odd number | Protec

Before writing any program you just imagine about output screen first. Like what input to be given, and output to be displayed. Let's have a look at the below example.

  1. INPUT

  2. Enter any number to check even or odd: 15

  OUTPUT

15 is odd number.

Required knowledge for this exercise

Logic to check whther number is even or odd using if...else:

Remember: If any number is exactly divisible by 2then it is called even number otherwise odd. 
1) Input any number from user and store it in variable num using scanf()
2) Check the given number is exactly divisible by 2or not using modulo % operator. Likeif(num % 2 == 0)if it's remainder is equal to0then number is even otherwise odd. Since we know that, modulo %operator always returns remainder.

Program to chek whether a number is even or odd using if...else: 

  1. /* C program to whether number is even or odd */ #include <stdio.h> int main() { int num; /* Input number from user */ printf("Enter any number to check even or odd: "); scanf("%d", &num); /* Check if the number is divisible by 2 then it is even */ if(num % 2 == 0) { /* If it's remainder is zero then */ printf("d% is Even number.", num); } else { /* If it's remainder is Nonezero then */ printf("%d is Odd number.", num); } return 0; }

Please note: if(num % 2 == 0) Here, symbol%is a modulo operator not a percent sign. 

Output:
  1. Enter any number to check even or odd: 15
  2. 30 is odd number.









Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us