c++ program to find power of a number using for loop || power of a number using for loop

Write a program to find x to the power n (i.e. x^n). Take x and n from the user. You need to print the answer.

Input format :

Two integers x and n (separated by space)

Output Format :

x^n (i.e. x raise to the power n)

Sample Input 1 :
 3 4

Sample Output 1 :
81

Sample Input 2 :
 2 5

Sample Output 2 :
32

c program to find power of a number using for loop,power of a number in c++














C++ Code :

#include<iostream>
using namespace std;

int main()
{

   int x, n, i, pow=1;
   cin>>x>>n;
   for(i=n;i>0;i--)
   {
     pow=pow*x;
   }
   cout << pow;




SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment