Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Power Function

  1. #1
    New Coder
    Join Date
    Nov 2011
    Location
    Pakistan
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Power Function

    #include<iostream.h>
    #include<conio.h>
    int Pow(int , int);
    main(){
    int num, pow, res;
    cout<<"Enter the number u want the power: ";
    cin>>num;
    cout<<endl
    <<"enter the power: ";
    cin>>pow;
    cout<<endl;
    res=Pow(num,pow);
    cout<<"The power of "<<num<<" is "<<pow<<" and result is "<<res<<endl;
    getch();
    }
    int Pow(int base, int n)
    {
    int i,p;
    p=base;
    if(base==0)
    {
    return 1;
    }
    else
    {
    for(i=1;i<=n-1;i++)
    {
    p=p*base;
    }
    return p;
    }
    }


    If power is set as 0, its not generating the result.
    Help me out....

  • #2
    New Coder
    Join Date
    Nov 2011
    Location
    Pakistan
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I got it myself.....

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    In the future always post code using code or php tags. Read here for more info
    http://www.codingforums.com/misc.php?do=bbcode#code
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •