Showing posts with label Odd or Even. Show all posts
Showing posts with label Odd or Even. Show all posts

C program to check whether a number entered by user is even or odd.

C program to check whether a number entered by user is even or odd.



#include <stdio.h>
int main(){
      int num;
      printf("Enter an integer you want to check: ");
      scanf("%d",&num);
      if((num%2)==0)      /* Checking whether remainder is 0 or not. */
           printf("%d is even.",num);
      else
           printf("%d is odd.",num);
      return 0;
}

C++ Program to square an even number or cube an odd number.

C++ Program to square an even number or cube an odd number.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"Enter a number: ";
cin>>a;
if(a%2==0)
cout<<"The sqaure is: "<<a*a;
else
cout<<"The cube is: "<<a*a*a;
getch();
}

C++ Program to add 2 numbers and tell if it's odd/even.

C++ Program to add 2 numbers and tell if it's odd/even.




#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter first number: ";
cin>>a;
cout<<"Enter second number: ";
cin>>b;
a=a+b;
cout<<"The sum is: "<<a<<endl;
if(a%2==0)
cout<<"The sum is even";
else
cout<<"The sum is odd";
getch();
}

C++ Program to enter 'n' numbers and display no. of odd, even and numbers entered till user wishes.

C++ Program to enter 'n' numbers and display no. of odd, even and numbers entered till user wishes.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=0,b,o=0,e=0;
char z;
do
{
++a;
cout<<"Enter a number: ";
cin>>b;
if(b%2==0)
++e;
else
++o;
cout<<"Enter another number? (y/n): ";
cin>>z;
}
while(z=='y'||z=='Y');
cout<<"Number of number entered: "<<a<<endl;
cout<<"Number of even numbers: "<<e<<endl;
cout<<"Number of odd numbers: "<<o<<endl;
getch();
}

C - Determine If a Number is Odd or Even

How to write a C program to determine if a number is odd or even ?


Info! C program to determine if a number is odd or even
Solution:
#include <stdio.h>

int main()
{
int x;

scanf("%d", &x);

if(x % 2 == 0)
printf("Even");
else
printf("Odd");

return 0;
}

This C Program Determine If a Number is Odd or Even