Check give number is Even or Odd
#include<iostream.h>
#include<conio.h>
void main()
{
int no;
clrscr();
cout<<"Enter any num: ";
cin>>no;
if(no%2==0)
{
cout<<"Even num";
}
else
{
cout<<"Odd num";
}
getch();
}
#include<iostream.h> #include<conio.h> void main() { int no; clrscr(); cout<<"Enter any num: "; cin>>no; if(no%2==0) { cout<<"Even num"; } else { cout<<"Odd num"; } getch(); }
Output
Enter any num : 5
Odd num
Enter any num : 5 Odd num
Swap two numbers using third variables
Example
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"Enter value of a: ";
cin>>a;
cout<<"Enter value of b: ";
cin>>b;
c=a;
a=b;
b=c;
cout<<"After swap a: "<<a<<"b: "<<b;
getch();
}
#include<iostream.h> #include<conio.h> void main() { int a,b,c; clrscr(); cout<<"Enter value of a: "; cin>>a; cout<<"Enter value of b: "; cin>>b; c=a; a=b; b=c; cout<<"After swap a: "<<a<<"b: "<<b; getch(); }
Output
Enter value of a: 10
Enter value of b: 20
After swap a: 20 b: 10
Enter value of a: 10 Enter value of b: 20 After swap a: 20 b: 10