Posts

Showing posts with the label Write a C Program to accept an integer and check if it is Even or Odd.

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: Save the file as slip6a.c . Open a terminal and navigate to the file location....