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 calculate simple interest.

C++ Program to calculate simple interest.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a,b,c,d,e;
cout<<"Enter principal: ";
cin>>a;
cout<<"Enter rate% : ";
cin>>b;
cout<<"Enter time in years: ";
cin>>c;
a=a*b*c/100;
cout<<"The simple interest is: "<<a;
getch();
}

C++ Program to check if a year is a leap year.

C++ Program to check if a year is a leap year.




#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter a year: ";
cin>>a;
if(a%400==0)
cout<<"It's a leap year"<<endl;
else if(a%100==0)
cout<<"It's not a leap year"<<endl;
else if(a%4==0)
cout<<"It's a leap year"<<endl;
else
cout<<"It's not a leap year"<<endl;
getch();
}

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 swap values of two variable without using third.

C++ Program to swap values of two variable without using third.



#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;
b=a-b;
a=a-b;
cout<<"The first number is: "<<a<<endl;
cout<<"The second number is: "<<b;
getch();
}

C++ Program to display the sum of this series: 1+1/2+1/3....1/n.

C++ Program to display the sum of this series: 1+1/2+1/3....1/n.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a,b=0,i;
cout<<"Enter a number: ";
cin>>a;
for(i=1;i<=a;i++)
b=b+(1/i);
cout<<"The sum of the series is: "<<b;
getch();
}