Program to calculate power of number

/* Program: To calculate x^n */
    #include <iostream.h>
    #include <math.h>
    void main()
    {
        int num , power , result ;
        cout<<"Enter the number and the power :\n";
        cin>>num>>power;
        result = pow (num,power) ;
        cout<<"Result : "<<result;
    }


-------------------------------------------------

 /*Program: To calculate x^n without using the pow() function */
    #include <iostream.h>
    void main()
    {
        int i , number , power , result ;
        cout<<"Enter the base number :\n";
        cin>>number;

        cout<<"Enter the power :\n";
        cin>>power;

        result = number ;

        for (i=1 ; i<power ; i++)
            result = result * number ;

        cout<<"Result : "<<result;
    }

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|