C++ tutorial, C++ programs, C++ Exercises, C++ Example Programs

Thursday, October 31, 2013

Program Find Out Square Cube of Number




/*

Program to input a number, then display its square and cube.
(c) Www.EasyCppProgramming.Blogspot.Com
*/


#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
     int num, square, cube;

     clrscr();

     cout<<"Enter a number=";
     cin>>num;

     cout<<"\n Method 1: By Multiplication operator *\n";
    
     square = num * num;
     cube   = num * num * num;
     cout<<"\n The number="<<num<<"    Square="<<square<<"   Cube="<<cube;


     cout<<"\n\n Method 2: By pow function of math.h \n";
    
     square = pow(num,2);
     cube   = pow(num,3);
     cout<<"\n The number="<<num<<"    Square="<<square<<"   Cube="<<cube;

     getch();

     }

Output of the program execution:


Share:

Tuesday, October 29, 2013

Program Exchange Values Without Third Variable


#include<iostream.h>
#include<conio.h>
void main()
{
     int v1, v2;

     cout<<"Enter value of first variable:";
     cin>>v1;
  
     cout<<"Enter value of second variable:";
     cin>>v2;

     cout<<"The values before swapping are: \n Varible 1="<<v1<<" Variable 2="<<v2;
     v2 = v1+v2;
     v1 = v2-v1;
     v2 = v2-v1;

     cout<<"\n The values after swapping are: \n Varible 1="<<v1<<" Variable 2="<<v2;  
     
      getch();

     }
Share:

Friday, October 25, 2013

Program to Swap Values of Two Variables




#include<iostream.h>
#include<conio.h>
void main()
{
     int v1, v2, temp;

     cout<<"Enter value of first variable:";
     cin>>v1;
   
     cout<<"Enter value of second variable:";
     cin>>v2;

     cout<<"The values before swapping are: \n Varible 1="<<v1<<" Variable 2="<<v2;
     temp = v1;
     v1 = v2;
     v2 = temp;

     cout<<"\n The values after swapping are: \n Varible 1="<<v1<<" Variable 2="<<v2;   
      
      getch();

     }
   
Share:

EasyCPPprogramming.blogspotcom

Labels