Pages

Tuesday 22 March 2011

PROGRAM TO PRINT SERIES

DESCRIPTION-:THIS PROGRAM PRINTS THE SERIES LIKE
N .......5 4 3 2 1 0 1 2 3 4 5........N.
PROGRAM-:   
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n;
cout<<"enter the value of n";
cin>>n;
for(i=n;i>=0;i--)
{
cout<<i;
}
for(i=1;i<=n;i++)
{
cout<<i;
}
getch();
}

Monday 21 March 2011

PROGRAM TO CONVERT DECIMAL NUMBER TO BINARY

DESCRIPTION-:This program receive input as decimal number and then calculate its binary equivalent and then display the binary equivalent of that decimal number.
FOR EXAMPLE-:If we have input decimal number------
                                          23
Then it generate output as-----------------
                                       10111
                           
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i=0,j,d,a[10];
cout<<"enter the decimal number";
cin>>d;
while(d>0)
{
a[i]=d%2;
d=d/2;
i++;
}
cout<<"its binary equivalent is";
for(j=i-1;j>=0;j--)
{
cout<<a[j];
}
getch();
}

Saturday 19 March 2011

PROGRAM TO CALCULATE THE SUM OF EACH ROW AND EACH COLUMN AND TOTAL OF ALL ELEMENTS OF MATRIX

DESCRIPTION-: This program take matrix as input and again generate matrix as output in which sum of each row elements is placed in corrosponding row and also sum of each column elements is placed in corrosponding column and also calculate the total of all elements.
FOR EXAMPLE-:
If we have input matrix as-----

              2   3
              1   5

Then it generate output as--------

              2   3   5
              1   5   6
              3   8   11

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],m,n,i,j;
cout<<"enter the row and column of matrix";
cin>>m>>n;
cout<<"enter elements of array"<<"\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
for(i=0;i<m;i++)
{
a[i][n]=0;
for(j=0;j<n;j++)
{
a[i][n]=a[i][n]+a[i][j];
}
}
for(j=0;j<n;j++)
{
a[m][j]=0;
for(i=0;i<m;i++)
{
a[m][j]=a[m][j]+a[i][j];
}
}
a[m][n]=0;
for(i=0;i<m;i++)
{
a[m][n]=a[m][n]+a[i][n];
}
cout<<"\n";
for(i=0;i<m+1;i++)
{
cout<<"\n";
for(j=0;j<n+1;j++)
{
cout<<a[i][j]<<"\t";
}
}
getch();
}

PROGRAM TO FIND THE TRANSPOSE OF GIVEN MATRIX

DESCRIPTION-: This program takes matrix as input and then calculate the transpose of input matrix and after calculating transpose of matrix it generate output matrix.
FOR EXAMPLE-: If we have input matrix as--------

                                1   3   6
                                5   9   2
                                4   1   7

Then program generate output as---------

                                1   5   4
                                3   9   1
                                6   2   7


PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,m,n,a[10][10],b[10][10];
cout<<"enter the number of rows and column of matrix"<<"\n";
cin>>m>>n;
cout<<"enter the value of elements of matrix";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"entered matrix is"<<"\n";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
{
cout<<a[i][j]<<"\t";
}
}
cout<<"\n transpose of matrix is"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
b[i][j]=a[j][i];
}
}
for(i=0;i<n;i++)
{
cout<<"\n";
for(j=0;j<m;j++)
{
cout<<b[i][j]<<"\t";
}
}
getch();
}

PROGRAM TO MULTIPLY TWO MATRICES

DESCRIPTION-: This program takes two matrices as input then calculate the multiplication of input  matrices and then generate the output matrix.The output matrix contains the multiplication of input matrices.
FOR EXAMPLE-:

If we have two input matrices as---------

              2   1                                       3   1   2
              1   3                                       1   2   3
              3   1
Then program generate output as--------
                      7   4   7
                      6   7   11
                     10  5   9

PROGRAM-:
#include<iostream.h> 
#include<conio.h>
void main()
{
clrscr();
int i,j,m,n,p,q,a[10][10],b[10][10],c[10][10];
cout<<"enter row and column of matrix A";
cin>>m>>n;
cout<<"\n enter the row and column of matrix B";
cin>>p>>q;
if(n!=p)
{
cout<<"multiplication not possible";
}
else
{
cout<<"enter value of elements of matrix A"<<"\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"enter values of elements of matrix B"<<"\n";

for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
cin>>b[i][j];
}
}
cout<<"values of elements of matrix A are"<<"\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<a[i][j];
}
cout<<"\n";
}
cout<<"values of elements of matrix B are"<<"\n";
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
cout<<"\t";
cout<<b[i][j];
}
cout<<"\n";
}
cout<<"multiplication  of two matrix is:";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<q;j++)
{
c[i][j]=0;
for(int k=0;k<p;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
cout<<c[i][j]<<"\t";
}
 }
}
getch();
}

PROGRAM TO SUBTRACT TWO MATRIX

DESCRIPTION- This program takes two matrices as input and then generate the output matrix after subtracting the two input matrices.The order of input matrix must be same.
FOR EXAMPLE-: If we have two input  matrices as---------

             2   3   1                                 2   2   1
             1   5   7                                 1   4   6
             2   8   1                                 1   3   1

Then program generate output as---------
                                  0   1   0
                                  0   1   1
                                  1   5   0

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n,a[10][10],b[10][10],c[10][10];
cout<<"enter the order of matrix A";
cin>>n;
cout<<"enter value of elements of matrix A"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"enter the order of matrix B";
cin>>n;
cout<<"enter values of elements of matrix B"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>b[i][j];
}
}
cout<<"values of elements of matrix A are"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<a[i][j];
}
cout<<"\n";
}
cout<<"values of elements of matrix B are"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<b[i][j];
}
cout<<"\n";
}
cout<<"subtraction of matrix A and B is"<<"\n";
for(i=0;i<n;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]-b[i][j];
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}
getch();
}

PROGRAM TO ADD TWO MATRIX

DESCRIPTION-:This program takes two matrices as input and then generate the output matrix which contain the addition of two input matrices.The order of two input matrices must be same.
FOR EXAMPLE-:  If we have two input matrices as-------
               2   6   1                           2   1   5
               3   1   3                           7   2   1
               1   0   5                           1   7   0


Then program generate output as-------
                                     4   7   6

                                    10  3   4
                                     2   7   5

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n,a[10][10],b[10][10],c[10][10];
cout<<"enter the order of matrix A";
cin>>n;
cout<<"enter value of elements of matrix A"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"enter the order of matrix B";
cin>>n;
cout<<"enter values of elements of matrix B"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>b[i][j];
}
}
cout<<"values of elements of matrix A are"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<a[i][j];
}
cout<<"\n";
}
cout<<"values of elements of matrix B are"<<"\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<b[i][j];
}
cout<<"\n";
}
cout<<"addition of matrix A and B is"<<"\n";
for(i=0;i<n;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}
getch();
}

PROGRAM TO DISPLAY THE ELEMENT OF 2-D ARRAY

DESCRIPTION-:This program display the elements of two dimensional array.means that it display elements of array in the form of matrix.
In this program we must specifies the number of rows and columns in the array.

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,m,n,a[100][100];
cout<<"enter number of rows and column in array"<<"\n";
cin>>m>>n;
cout<<"enter value of elements of array"<<"\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<"values of 2-D array element is"<<"\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<"\t";
cout<<a[i][j];
}
cout<<"\n";
}
getch();
}

PROGRAM TO FIND SUM OF ELEMENTS OF ARRAY USING FUNCTION

DESCRIPTION-: This program calculate the sum of all the elements of an array with the help of function.
In this program firstly we entered the value of elements of an array and after this the program calculate the sum of elements of array and display the sum at last.
FOR EXAMPLE-: If we have elements of array as-----
                                  12   4   7   1   7   3

Then program generate output as-------
                                   sum=34

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void sum(int a[],int n);
void main()
{
clrscr();
int n,a[10];
cout<<"enter the number of elements in array";
cin>>n;
cout<<"enter value of elements of array"<<"\n";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"entered value of array element is"<<"\n";
for(i=0;i<n;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<"\n";
}
sum(a,n);
getch();
}
void sum(int a[],int n)
{
int sum=0;
for(int i=0;i<n;i++)
{
sum=sum+a[i];
}
cout<<"sum of elements ="<<sum;
}

PROGRAM TO SORT THE ELEMENTS IN ARRAY IN ASCENDING ORDER USING FUNCTION

DESCRIPTION-: This program arrange the elements of an array in ascending order.In this firstly we enter the elements of an array and after entering the elements of array this program sort the elements of an array in ascending order.
FOR EXAMPLE-:

If we have elements of an array as-------------
                    5    2    12    45    99    9
Then program generate the output as----------
                    2    5    9    12    45    99


PROGRAM-:
#include<iostream.h>
#include<conio.h>
void sort(int a[],int n);
void main()
{
clrscr();
int n,a[10];
cout<<"enter number of elements in array";
cin>>n;
cout<<"\n enter the value of elements of array";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"enter value of elements of array are"<<"\n";
for(i=0;i<n;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<"\n";
}
cout<<"elements in ascending order are"<<"\n";
sort(a,n);
getch();
}
void sort(int x[],int y)
{

for(int i=0;i<y;i++)
{
for(int j=0;j<y;j++)
{
if(x[i]<x[j])
{
int temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}
}
for(i=0;i<y;i++)
{
cout<<x[i]<<"\n";
}
}

PROGRAM TO SORT THE ELEMENTS IN ARRAY IN DESACENDING ORDER

DESCRIPTION-: This program arrange the elements of an array in descending order.In this firstly we enter the elements of an array and after entering the elements of array this program sort the elements of an array in descending order.
FOR EXAMPLE-:


If we have elements of an array as-------------

                    5    2    12    45    99    9

Then program generate the output as----------

                    99    45    12    9    5    2



PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,a[10],temp;
cout<<"enter number of elements in array";
cin>>n;
cout<<"\n enter the value of elements of array";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"enter value of elements of array are"<<"\n";
for(i=0;i<n;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<"\n";
}
cout<<"elements in ascending order are"<<"\n";
for(i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<n;i++)
{
cout<<a[i]<<"\n";
}
getch();
}

PROGRAM TO SORT THE ELEMENTS IN ARRAY IN ASCENDING ORDER

DESCRIPTION-: This program arrange the elements of an array in ascending order.In this firstly we enter the elements of an array and after entering the elements of array this program sort the elements of an array in ascending order.
FOR EXAMPLE-:


If we have elements of an array as-------------

                    5    2    12    45    99    9

Then program generate the output as----------

                    2    5    9    12    45    99




PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,a[10],temp;
cout<<"enter number of elements in array";
cin>>n;
cout<<"\n enter the value of elements of array";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"enter value of elements of array are"<<"\n";
for(i=0;i<n;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<"\n";
}
cout<<"elements in ascending order are"<<"\n";
for(i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for(i=0;i<n;i++)
{
cout<<a[i]<<"\n";
}
getch();
}

PROGRAM TO FIND GREATEST NUMBER IN ARRAY

DESCRIPTION-: This program calculate the greatest number in the given array.In this we firstly enter the elements of an array and after entering the elements of an array the program finds the greatest element in array and produces output contain the largest number in the array.
FOR EXAMPLE-: If we enter elements of array as--------
                                2    34    1    67    99    45    33             

Then program produces output as---------
                          gretest number in array is  99

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,a[10];
cout<<"enter number of elements in array";
cin>>n;
cout<<"enter the value of array elements"<<"\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"\n value of elements of array are";
for(i=0;i<n;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<"\n";
}
int max=a[0];
for(i=1;i<n;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
cout<<"largest number is"<<max;
getch();
}

PROGRAM TO CALCULATE AVERAGE OF 'n' ELEMENTS USING ARRAY

DESCRIPTION-: This program calculate the average of all the elements of an input array.this program firstly calculate the sum of the elements of array and after calculating the sum it calculate the average of elements of array by dividing sum to the number of elements in an array.
FOR EXAMPLE-: If we have elements of array as-------
                      2    4    22    54    8    1

Then it generates output as------
               average=15.16
        
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,sum=0,a[20];
float avg;
cout<<"enter number of elements in array";
cin>>n;
cout<<"enter value of elements of array"<<"\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"sum of elements of array are"<<"\n";
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
cout<<"sum ="<<sum<<"\n";
avg=sum/n;
cout<<"average ="<<avg;
getch();
}

PROGRAM TO PRINT ELEMENTS OF ARRAY

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,a[20],i;
cout<<"enter the number of element in array"<<"\n";
cin>>n;
cout<<"enter the elements of array"<<"\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"entered elements of array are";
for(i=0;i<n;i++)
{
cout<<"a["<<i<<"]="<<a[i]<<"\n";
}
getch();
}

Friday 18 March 2011

PROGRAM OF FIBONACCI SERIES

DESCRIPTION-:This program display the Fibonacci series.A fibonacci series is one in which first term is 0 and second term is 1 and the next term is the sum of the two previous term and so-on.
This program display the Fibonacci series according to the users requirement OR upto user entered number.
FOR EXAMPLE-: If the user enter a number 5

then it generate fibonacci series as------
                        0    1    1    2    3    5    8

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,first=0,second=1,third;
cout<<"how many no u want to print";
cin>>n;
cout<<"fibonacci series"<<"\n";
cout<<first<<" "<<second<<"\n";
for(i=2;i<=n;i++)
{
third=first+second;
cout<<third<<"\n";
first=second;
second=third;
}
getch();

}

PROGRAM TO PRINT TABLE

DESCRIPTION-:This program print the table of the number entered by the user.
PROGRAM-:
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int i,n;
cout<<"Enter to print table of given no";
cin>>n;
cout<<"the table of given number is"<<"\n";
for(i=1;i<=10;i++)
cout<<"\t\t"<<n<<"*"<<i<<"="<<n*i<<"\n";
getch();
}

PROGRAM TO CONVERT TEMPERATURE

DESCRIPTION-:This program convert the temperature from Fahrenheit to the Celsius OR vice-versa according to the user need.
PROGRAM-:   
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int choice;
float temp,conv;
cout<<"temperature conversion menu"<<"\n";
cout<<"1.fahrenheit to celsius"<<"\n";
cout<<"2.celsius to fahrenheit"<<"\n";
cout<<"enter ur choice(1-2)";
cin>>choice;
if(choice==1)
{
cout<<"enter temp. in fahrenheit";
cin>>temp;
conv=(temp-32)/1.8;
cout<<"temp in celsius";
cout<<conv;
}
else
{
cout<<"enter temp. in celsius";
cin>>temp;
conv=(1.8*temp)+32;
cout<<conv;
}
getch();
}

PROGRAM TO FIND THE LARGEST NUMBER USING IF STATEMENT

DESCRIPTION-:This program accepts three numbers as input and then calculate the largest number between the three number using the if statement and at last it display that largest number.
FOR EXAMPLE-: If we entered three number as-------
                                  23       45      99
 Then program generates output s---------
 largest number is     99
 
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int max,a,b,c;
cout<<"enter three numbers:";
cin>>a>>b>>c;
max=a;
if(b>max)
max=b;
if(c>max)
max=c;
cout<<"the largest  of " <<a<<", "<<b<<" and "<<c<<" is " <<max;
getch();
}

PROGRAM OF FUNCTION WITH PARAMETERS AND WITH RETURN VALUE

DESCRIPTION-:Function with parameters and with return value contains a parameters in the "function call" and return the value in the function definition.The value returned in the function definition is the final result or the output of the program.
Here in below we have a program which calculate the sum of two numbers by passing parameters in the function call and returning value in the function defination as output.
 
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
int max(int,int);
cout<<"enter two numbers";
cin>>a>>b;
c=max(a,b);
cout<<"greatest number is"<<c;
getch();
}
int max(int x,int y)
{
if(x>y)
return(x);
else
return(y);
}

PROGRAM TO CALCULATE THE SUM OF THREE NUMBERS USING FUNCTION

DESCRIPTION-:tThe program calculate the sum of the three numbers using function.In this we pass three arguments or parameters in the function call and the sum of three number is return by the function definition block.
FOR EXAMPLE-:If we entered three number as--------

                              23    45    2
Then program generate output as-------------
                                The sum of x,y,z is=70

PROGRAM-:
#include<iostream.h>
#include<conio.h>
float sum(float,float,float);
void main()
{
clrscr();
float x,y,z;
cout<<"enter the value of three no"<<"\n";
cin>>x>>y>>z;
float total;
total=sum(x,y,z);
cout<<"sum of x,y,z="<<total<<"\n";
getch();
}
float sum(float a,float b,float c)
{
float temp;
temp=a+b+c;
return(temp);
}

PROGRAM TO CALCULATE SQUARE USING FUNCTION

DESCRIPTION-:This program calculate the square of 'n' numbers with the help of function.In this the function call is place under the for loop as we want to calculate the square of 'n' numbers not only one number and function definition returns the square of numbers.
FOR EXAMPLE-: If we enter the value of n-------
                                         3
 Then program generate output as---------------
                          i=0        square=0                       
                          i=1        square=1
                          i=2        square=4
                          i=3        square=9

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void square(int);
void main()
{
clrscr();
int i,n;
cout<<"enter a value for n";
cin>>n;
for(i=0;i<=n;i++)
{
square(i);
getch();
}
}
void square(int x)
{
int y;
y=x*x;
cout<<"i="<<x<<"square="<<y<<"\n";
}

PROGRAM OF FUNCTION WITH NO PARAMETERS AND NO RETURN VALUES

DESCRIPTION-:Program with no parameters and without returning any value contains no parameters in function call and also not return any value in the function definition block.For these type of program also we do not pass any parameter or argument in function declaration.
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
void print();
print();
cout<<"no parameters and no return type";
print();
getch();
}
void print()
{
for(int i=1;i<=10;i++)
{
cout<<"*";
}
}

PROGRAM TO FIND MINIMUM OF FOUR NUMBER USING FUNCTION

DESCRIPTION-:The program finds the greater between four number using the function.In program we pass the four parameters in the function call but in pair(means in function call we have two pair).This program firstly calculate the minimum number in first pair and then calculate the minimum number in second pair.After this program calculate the minimum number between the output of first and second pair.
FOR EXAMPLE-:If we enter four number as-------

                                     23    34    21    39
Then it generate output as----------
firstly it calculate minimum number between  23    and    34   =23
then it calculate minimum number between    21    and    39   =21
at last it calculate the minimum number between  21    and    23    =21

PROGRAM-:
#include<iostream.h>
#include<conio.h>
int min(int,int);
void main()
{
clrscr();
int a,b,c,d;
cout<<"enter four integers";
cin>>a>>b>>c>>d;
cout<<"minimun no. ="<<min(min(a,b),min(c,d));
getch();
}
int min(int x,int y)
{
return((x<y)?x:y);
}

PROGRAM TO FIND MINIMUM OF FOUR NUMBER USING FUNCTION

PROGRAM-:
#include<iostream.h>
#include<conio.h>
int min(int,int);
void main()
{
clrscr();
int a,b,c,d;
cout<<"enter four integers";
cin>>a>>b>>c>>d;
cout<<"minimun no. ="<<min(min(a,b),min(c,d));
getch();
}
int min(int x,int y)
{
return((x<y)?x:y);
}

PROGRAM OF INLINE FUNCTION

DESCRIPTION-:INLINE function is one which increase the performance of function in very large programs.Actually it replaces the function definition with the function call and with this the program control does not transfer to the function definition at each time when the function call is execute  thus increases the performance.


PROGRAM-:
#include<iostream.h>
#include<conio.h>
inline int max(int x,int y)
{
return(x>y?x:y);
}
void main()
{
clrscr();
int a,b,c;
cout<<"enter two numbers";
cin>>a>>b;
c=max(a,b);
cout<<"greatest of two number is"<<c;
getch();
}

PROGRAM OF FUNCTION OVERLOADING

DESCRIPTION-:IN Function overloading we use same function name for multiple purpose.Thus in function defination we have same function name the only difference is the arguments or parameters.The arguments pass in program defination is different and if we have same arguments in two function definitions then it will generate the error.
Following is the program of the function overloading which calculate the area of square,rectangle and triangle.
In this we have same function name"area" but arguments pass to them are different.
PROGRAM-:
#include<iostream.h>
#include<conio.h>
#include<math.h>
void area(int);
void area(int,int);
void area(int,int,int);
void main()
{
clrscr();
float a,b,c,le,br,side;
cout<<"enter the side of square";
cin>>side;
cout<<"enter length and breadth of rectangle";
cin>>le>>br;
cout<<"enter parameter a,b,c of traingle";
cin>>a>>b>>c;
area(side);
area(le,br);
area(a,b,c);
getch();
}
void area(int x)
{
int a;
a=x*x;
cout<<"area of square is"<<a<<"\n";
}
void area(int x,int y)
{
int b;
b=x*y;
cout<<"area of rectangle is"<<b<<"\n";
}
void area(int x,int y,int z)
{
float s=(x+y+z)/2;
float ar;
ar=sqrt(s*(s-x)*(s-y)*(s-z));
cout<<"area of triangle using HERO formula is"<<ar;
}

PROGRAM TO FIND THE FACTORIAL USING THE FUNCTION

DESCRIPTION-:This program calculate the factorial of the given number using the function.In function call we pass the one parameter and in function definition we use for loop to calculate the factorial of the given number.
FOR EXAMPLE-:If we enter number as--------
                                                            5
Then it generate output as---------------
                                     Factorial of number is =120


PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int fact(int);
int n,i,k;
cout<<"enter any number";
cin>>n;
k=fact(n);
cout<<"factorial of number is=  "<<k;
getch();
}
int fact(int x)
{
int fact=1;
if(x==0||x==1)
{
cout<<"factorial of number is"<<fact;
}
else
{
for(int i=2;i<=x;i++)
{
fact=fact*i;
}
}
return(fact);
}

PROGRAM OF FUNCTION WITH DEFAULT ARGUMENTS

DESCRIPTION-:Default arguments are one who's values are initialized in the function definition(means when we declare the argument in function definition).The value of all the default arguments remains same throughout the program unless it is changed in the function call.
As explain in the below program how function call effect the default arguments.

PROGRAM-:
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void volume(int l=10,int w=10,int h=10);
void main()
{
clrscr();
volume();   //equivalent to (10,10,10)//
volume(5);  //equivalent to (5,10,10)//
volume(5,6);  //equivalent to (5,6,10)//
volume(6,4,5);  //equivalent to(6,4,5)//
getch();
}
void volume(int l,int w,int h)
{
cout<<"volume is"<<l*w*h<<"\n";
}

PROGRAM TO FIND THE SUM USING FUNCTION

DESCRIPTION-:This program calculate the sum of two numbers with the help of the function.In this program we pass two arguments in the function call and function definition returns the sum of the entered two numbers.In function call we pass two arguments of which we want to calculate the sum.
FOR EXAMPLE-:If we enter two numbers as-------
                                           2       4

Then it generate output as--------
                                   sum=6                       


PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
void sum(int,int);
cout<<"enter two numbers";
cin>>a>>b;
sum(a,b);
getch();
}
void sum(int x,int y)
{
int z;
z=x+y;
cout<<"sum="<<z;
}

PROGRAM FOR SWITCH STATEMENT

COMMENT-:THIS PROGRAM FINDS THE ADDITION,MULTIPLICATION,DIVISION,
SUBTRACTION OF TWO NUMBER USING THE SWITCH STATEMENT
DEPENDING UPON THE CHOICE OF THE USER    
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"enter the value of two numbers";
cin>>a>>b;
cout<<"1.addition"<<"\n";
cout<<"2.multiplication"<<"\n";
cout<<"3.division"<<"\n";
cout<<"4.subtraction"<<"\n";
int choice;
cout<<"enter your choice";
cin>>choice;
switch(choice)
{
case 1:c=a+b;
cout<<"sum is"<<c;
break;
case 2:c=a*b;
cout<<"multiplication is"<<c;
break;
case 3:c=a/b;
cout<<"division is"<<c;
break;
case 4:c=a-b;
cout<<"subtraction is"<<c;
break;
default:cout<<"invalid choice:";
}
getch();
}

PROGRAM TO CALCULATE THE SQUAREROOT OF THE GIVEN NUMBER

DESCRIPTION-:This program calculates the square root of the entered number.It may be sure that the value of entered number should be greater than the 0.As the value of square root for negative number is "imaginary".
FOR EXAMPLE-: If we enter element as------------
                                            64
 Then program generate output-------------
                  square root=8
 
PROGRAM-:
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int a;
float squareroot,cuberoot;
cout<<"enter the number";
cin>>a;
cout<<"\n"<<"square root of the number is"   ;
squareroot=sqrt(a);
cout<<squareroot;
getch();
}

PROGRAM TO CALCULATE SQUARE AND CUBE OF A NUMBER

COMMENT-:THIS PROGRAM DISPLAY THE SQUARE,CUBE
OF THE NUMBERS
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,square,cube;
cout<<"enter the value of n";
cin>>n;
cout<<"cube and square of number is"<<"\n";
for(i=1;i<=n;i++)
{
square=i*i;
cube=i*i*i;
cout<<"\t\t"<<i<<"\t\t"<<square<<"\t\t"<<cube<<"\n";
}
getch();
}

PROGRAM TO CALCULATE THE SIMPLE INTEREST

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float p,r,t,si;
cout<<"enter principle,rate,interest";
cin>>p>>r>>t;
si=(p*r*t)/100;
cout<<"simple interest is"<<si;
getch();
}

PROGRAM TO FIND THE SUM OF TWO NUMBER

DESCRIPTION-:THIS PROGRAM FINDS THE SUM OF TWO NUMBERS
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
cout<<"enter the value of two numbers";
cin>>a>>b;
c=a+b;
cout<<"sum of two number is"<<c;
getch();
}

PROGRAM TO CALCULATE THE SUM OF DIGIT OF NUMBER

DESCRIPTION-:THIS PROGRAM FINDS THE SUM OF THE DIGITS
OF THE ENTERED NUMBER.
FOR EXAMPLE IF WE HAVE NUMBER 123
THEN SUM=1+2+3=6.  
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,rem,sum=0;
cout<<"enter the value of n";
cin>>n;
while(n>0)
{
rem=n%10;
n=n/10;
sum=sum+rem;
}
cout<<"sum of digit is"<<sum;
getch();
}

PROGRAM TO PRINT SERIES

DESCRIPTION-:THIS PROGRAM PRINT SERIES AS
1+X^2+X^4+X^6...............


PROGRAM-:
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int n,x,i,sum=1,k;
cout<<"enter no of elements";
cin>>n;
cout<<"enter value of x";
cin>>x;
k=2*n-1;
for(i=2;i<=k;i=i+2)
{
sum=sum+pow(x,i);
}
cout<<"sum is"<<sum;
getch();
}

PROGRAM TO PRINT SERIES

DESCRIPTION-:THIS PROGRAM PRINT SERIES AS
1 2 3 4
1 2 3
1 2
1

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n;
cout<<"enter the value of n";
cin>>n;
for(i=n;i>0;i--)
{
cout<<"\n";
for(j=1;j<=i;j++)
{
cout<<j;
}
}
getch();
}

PROGRAM TO PRINT SERIES

DESCRIPTION-:THIS PROGRAM PRINT THE SERIES AS
4 3 2 1
3 2 1
2 1
1

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n;
cout<<"enter the value of n";
cin>>n;
for(i=n;i>0;i--)
{
cout<<"\n";
for(j=i;j>0;j--)
{
cout<<j;
}
}
getch();
}

PROGRAM TO PRINT SERIES

COMMENTS-:THIS PROGRAM PRINT SERIES AS
1
1 2
1 2 3
1 2 3 4


PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n;
cout<<"enterthe value of n";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<"\n";
for(j=1;j<=i;j++)
{
cout<<j;
}
}
getch();
}

PROGRAM TO PRINT SERIES

DESCRIPTION-:THIS PROGRAM PRINT THE SERIES AS
1
2 1
3 2 1
4 3 2 1 


PROGRAM-: 
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,n;
cout<<"enterthe value of n";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<"\n";
for(j=i;j>=0;j--)
{
cout<<j;
}
}
getch();
}

PROGRAM TO FIND THE ROOTS OF QUADRATIC EQUATION

DESCRIPTION-:THIS PROGRAM FINDS THE ROOT OF THE QUADRATIC EQUATION
Ax^2+Bx+C
IN THIS PROGRAM WE FIRST CALCULATE THE VALUE OF "D" FOR QUADRATIC EQUATION
IF THE VALUE OF D>0 THEN THE ROOTS ARE REAL AND HAVE DIFFERENT VALUE.
IF THE VALUE OF D=0 THEN BOTH THE ROOTS HAVE SAME VALUE.
 IF THE VALUE OF D<0 THEN THE ROOTS HAVE IMAGINARY VALUE.
PROGRAM-:
#include<iostream.h>
#include<math.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,x1,x2;
float d;
cout<<"enter the value of a,b,c"<<"\n";
cin>>a>>b>>c;
d=(b*b)-(4*a*c);
if(d==0)
{
x1=x2=(-b)/(2*a);
cout<<"roots are real and value is"<<x1<<"\n";
}
else if(d>0)
{
x1=(-b)+sqrt(d)/(2*a);
x1=(-b)-sqrt(d)/(2*a);
cout<<"the value of two roots are"<<"\n";
cout<<"x1="<<x1<<"\n"<<"x2="<<x2;
}
else
{
cout<<"roots are imaginary";
}
getch();
}

PRIME NUMBER PROGRAM

DESCRIPTION-:THIS PROGRAM IS USED TO CHECK WHETHER THE ENTERED
NUMBER IS PRIME OR NOT.
A PRIME NUMBER IS ONE WHICH IS NOT DIVISIBLE BY ANY OTHER
NUMBER EXCEPT ITSELF .FOR EXAMPLE 5,43,23,17.......
PROGRAM-:
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
int n;
char ch;
do
{

cout<<"enter the number";
cin>>n;

for (int i=2;i<=n/2;i++)
{
if(n%i==0)
{
cout<<"no is not prime";
goto start;
}
}
cout<<"no is prime";
start:
cout<<"u waana further continue(Y/y)";
cin>>ch;
}
while(ch=='y'||ch=='Y');
getch();
}

PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS PALINDROME OR NOT

DESCRIPTION-:THIS PROGRAM CHECKS WHETHER THE ENTERED NUMBER IS PALINDROME
OR NOT.PALINDROME NUMBER IS ONE WHOSE REVERSE IS SAME AS THAT
OF ENTERED GIVEN NUMBER.NOT
THIS PROGRAM FIRST CALCULATE THE REVERSE OF THE GIVEN NUMBER AND THEN CHECK WHETHER THE REVERSE OF NUMBER IS EQUAL TO THE ENTERED NUMBER,IF BOTH NUMBERS ARE SAME THEN THE ENTERED NUMBER IS PALINDROME ELSE.
FOR EXAMPLE-: IF WE ENTER ELEMENT AS--------
                                       123
 THEN IT GENERATE OUTPUT AS---------
          THE NUMBER IS NOT PALINDROME
 
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,m,i,rem,rev=0;
cout<<"enter the required number";
cin>>n;
m=n;
while(m>0)
{
rem=m%10;
m=m/10;
rev=rev*10+rem;
}
cout<<"reverse of number is"<<rev<<"\n";
if(rev==n)
{
cout<<"number is palindrome";
}
else
{
cout<<"number is not palindrome";
}
getch();
}

PROGRAM TO CONVERT LOWERCASE LETTER TO UPPERCASE

DESCRIPTION-:THIS PROGRAM CONVERT A LOWERCASE LETTER INTO
UPPERCASE LETTER.
FOR EXAMPLE-: IF WE ENTER INPUT LOWERCASE  LETTER AS------------
                                            r
THEN IT GENERATES OUTPUT AS-----------
                      THE UPPERCASE EQUIVALENT=R

PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char ch;
cout<<"enter the lowercase character"<<"\n";
cin>>ch;
char ch2=(ch>='a'&&ch<='z')?('A'+ch-'a'):ch;
cout<<"uppercase equivalent is   "<<ch2;
getch();
}

PROGRAM TO FIND LEAP YEAR

DESCRIPTION-:THIS PROGRAM CHECKS WHETHER THE
ENTERED YEAR IS LEAP OR NOT
PROGRAM-:

#include<iostream.h>
#include<conio.h>
void main()
{
int n;
cout<<"enter the year";
cin>>n;
if(n%4==0)
{
cout<<"entered year is leap year";
}
else
{
cout<<"the entered year is not leap year";
}
getch();
}

PROGRAM TO INTERCHANGE TWO NUMBERS

DESCRIPTION-:THIS PROGRAM INTERCHANGE THE TWO NUMBER WITHOUT USING THE THIRD VARIABLE.THIS PROGRAM ACCEPT TWO NUMBERS AS INPUT AND GENERATE TWO NUMBER IN OUTPUT BY SWAPPING THEIR VALUES.
PROGRAM-: 
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"enter  the value of a and b";
cin>>a>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"\n"<<"after interchanging value of"<<"a="<<a<<"\n"<<"b="<<b;
getch();
}

GREATER BETWEEN THREE NUMBERS USING TERNARY OPERATOR

DESCRIPTION-:THIS PROGRAM FINDS GREATER BETWEEN THREE NUMBERS WITH
THE HELP OF TERNARY OPERATOR .
SYNTAX FOR TERNARY OPERATOR IS-:
EXPRESSION 1?EXPRESSION 2:EXPRESSION 3;
TERNARY  OPERATOR IS ONE IN WHICH IF THE CONDITION IS TRUE(i.e EXPRESSION 1) THEN IT EXECUTE EXPRESSION 2, ELSE IT EXECUTE EXPRESSION 3.
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,d;
cout<<"enter three no.";
cin>>a>>b>>c;
d=((a>b&&a>c)?a:(b>a&&b>c)?b:c);
cout<<"greater no is"<<d;
getch();
}
DESCRIPTION-:THIS PROGRAM FINDS THE FACTORIAL OF THE GIVEN NUMBER
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,fact=1;
cout<<"enter the no. whose factorial is to be find";
cin>>n;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
cout<<"factorial of number is"<<fact;
getch();
}

PROGRAM TO CHECK WHETHER THE ENTERED NUMBER IS EVEN OR ODD

DESCRIPTION-:THIS PROGRAM CHECKS WHETHER THE GIVEN NUMBER IS
EVEN OR ODD
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cout<<"enter any number";
cin>>n;
if(n%2==0)
{
cout<<"number is even";
}
else
{
cout<<"number is odd";
}
getch();
}

PROGRAM TO CHECK WHETHER THE GIVEN NUMBER IS ARMSTRONG OR NOT

DESCRIPTION-: THIS PROGRAM FINDS THE ARMSTRONG NUMBER.
ARMSTRONG NUMBER IS ONE IN WHICH THE SUM
OF THE CUBES OF THE DIGITS IS EQUAL TO THE
NUMBER ITSELF.
FOR EXAMPLE 153
1^3+5^3+3^3=153       


PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,m,rem,sum=0;
cout<<"enter the required number";
cin>>n;
m=n;
while(m>0)
{
rem=m%10;
m=m/10;
sum=sum+rem*rem*rem;
}
if(sum==n)
{
cout<<"number is armstrong";
}
else
{
cout<<"number is not armstrong";
}
getch();
}
 
Copyright (c) 2010 Concepts Of C++. Design by WPThemes Expert

Blogger Templates and RegistryBooster.