Featured post

-Write C program to find even and odd number using macro

-Write C program to find even and odd number using macro #include<stdio.h> #define number(n)((n%2==0)?1:0) int main() { int num; printf("enter any number"); scanf("%d",&num); if(number(num)) printf("number is even"); else printf("number is odd"); return 0; } ***************************Output*********************** amr@amrj-virtual-machine:~$ gccevenodd.c amr@samr-virtual-machine:~$ ./a.out enter any number 2 number is evensmj@amr-virtual-machine:~$

Write a C Program to accept an integer and check if it is Even or Odd.

C Program to Check Even or Odd Number

πŸ–₯️ C Program to Check Even or Odd Number

Below is a simple C program that checks whether a given number is even or odd.

πŸ“œ Source Code:


#include <stdio.h>
void main()
{
    int num;
    printf("Enter number: ");
    scanf("%d", &num);

    if (num % 2 == 0)
    {
        printf("Number is even");
    }
    else
    {
        printf("Number is odd");
    }
}

πŸ–₯️ Output:


amr@amr-virtual-machine:~$ gcc slip6a.c
amr@amr-virtual-machine:~$ ./a.out
Enter number: 12
Number is even

πŸ”Ή Explanation:

  • The program takes an integer input from the user.
  • It checks whether the number is divisible by 2 using the modulus (%) operator.
  • If the remainder is 0, it prints "Number is even", otherwise, it prints "Number is odd".

πŸ“Œ Steps to Compile and Run:

  1. Save the file as slip6a.c.
  2. Open a terminal and navigate to the file location.
  3. Compile the program using: gcc slip6a.c -o output
  4. Run the executable: ./output

✅ This program is a simple way to check even and odd numbers in C. Hope you found it useful!

πŸ”” Follow for more C programming tutorials!

Comments

Popular posts from this blog

-Write C program to find even and odd number using macro

BCA (SCIENCE) JAVA PRACTICAL SLIPS PAGES.(JAVA) UNIVERSITY OF PUNE

How to OCR Text Extraction in Flutter Using Google ML Kit