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();
}

C++ Program to enter an amount and display no. of Rs.500,100,50,20,10,5,1 notes.

C++ Program to enter an amount and display no. of Rs.500,100,50,20,10,5,1 notes.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int long a;
cout<<"Enter amount: ";
cin>>a;
cout<<"No. of Rs. 500 notes: "<<a/500<<endl;
a=a%500;
cout<<"No. of Rs. 100 notes: "<<a/100<<endl;
a=a%100;
cout<<"No. of Rs. 50 notes: "<<a/50<<endl;
a=a%50;
cout<<"No. of Rs. 20 notes: "<<a/20<<endl;
a=a%20;
cout<<"No. of Rs. 10 notes: "<<a/10<<endl;
a=a%10;
cout<<"No. of Rs. 5 notes: "<<a/5<<endl;
a=a%5;
cout<<"No. of Re. 1 notes: "<<a/1;
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++ Program to calculate a^b.

C++ Program to calculate a^b.



#include<iostream.h>
#include<conio.h>
int pwr(int,int);
void main()
{
clrscr();
int a,d;
cout<<"Enter first number: ";
cin>>a;
cout<<"Enter second number: ";
cin>>d;
cout<<"A^B: "<<pwr(a,d);
getch();
}

pwr(int a,int d)
{
int i,b=1;
for(i=1;i<=d;i++)
b=b*a;
return b;
}

C++ Program to display prime numbers upto n.

C++ Program to display prime numbers upto n.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,z;
cout<<"Enter a number: ";
cin>>a;
cout<<"The prime numbers upto "<<a<<" are: "<<endl;
for(b=2;b<=a;b++)
{
z=0;
for(c=1;c<=b;c++)
{
if(b%c==0)
z++;
}
if(z==2)
cout<<b<<" ";
}
getch();
}

C++ Program to display first n terms of fibonacci series.

C++ Program to display first n terms of fibonacci series.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long a,b=0,c=1,d=1;
cout<<"Enter the number of terms of fibnoacci series to display: ";
cin>>a;
cout<<"The first "<<a<<" terms of fibonacci series are: "<<endl;
for(int i=0;i<=a;i++)
{
d=b+c;
b=c;
c=d;
cout<<d<<" ";
}
getch();
}

C++ Program to display a number's digits reversed.

C++ Program to display a number's digits reversed.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<"Enter a number to display it's digits reversed: ";
cin>>a;
a=(a%10)*(10)+(a/10);
cout<<"The reversed number is: "<<a;
getch();
}

C++ Program to display the sum of a number's digits.

C++ Program to display the sum of a number's digits.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"Enter a number to display sum of it's digits: ";
cin>>a;
b=a%10;
while(a!=0)
{
a=a/10;
c=a%10;
b=b+c;
}
cout<<"The sum of the digits is: "<<b;
getch();
}

Program to display the following pattern: 1 12 123 1234 12345

Write a C++ Program to Display the Following Pattern.


/* Program to display the following pattern:
1
12
123
1234
12345
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
cout<<j;
cout<<endl;
}
getch();
}

Program to display the following pattern: * ** *** **** *****

Write a C++ Program to Display the Following Pattern.



/* Program to display the following pattern:
    *
   **
  ***
 ****
*****
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1;i<=5;i++)
{
for(int j=4;j>=i;j--)
cout<<" ";
for(int k=1;k<=i;k++)
cout<<"*";
cout<<endl;
}
getch();
}

Program to display the following pattern: ********** ********** **********

Write a C++ Program to Display the Following Pattern.



/* Program to display the following pattern:
**********
**********
**********
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1;i<=3;i++)
{
for(int j=1;j<=10;j++)
cout<<"*";
cout<<endl;
}
getch();
}

Program to display the following pattern: * *** ***** ******* *********

Write a C++ Program to Display the Following Pattern.



/* Program to display the following pattern:
    *
   ***
  *****
 *******
*********
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1,l=4;i<=9;i+=2,l--)
{
for(int j=1;j<=l;j++)
cout<<" ";
for(int k=1;k<=i;k++)
cout<<"*";
cout<<endl;
}
getch();
}

Program to display the following pattern: 1 222 33333 4444444 555555555

Write a C++ Program to Display the Following Pattern.



/* Program to display the following pattern:
    1
   222
  33333
 4444444
555555555
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1,l=4,m=1;i<=9;i+=2,l--,m++)
{
for(int j=1;j<=l;j++)
cout<<" ";
for(int k=1;k<=i;k++)
cout<<m;
cout<<endl;
}
getch();
}