C Code

#include<stdio.h>
#include<conio.h>

void main()
{
  int x,n,result=1;
  clrscr();
  printf("Enter Number \"n\": ");
  scanf("%d",&n);
  printf("\nEnter Power to Raise \"x\": ");
  scanf("%d",&x);
  if(x > 0)
  {
    for(int i=0;i<=x;i++)
      result=x*n;
    printf("n Power x = %d",result);
  }
  else
  {
    printf("x must be a positive number");
  }
  getch();
}

C++ Code

#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
  int x,n,result=1;
  cout << "Enter Number \"n\": ";
  cin >> n;
  cout << "\nEnter Power to Raise \"x\": ";
  cin >> x;
  if(x > 0)
  {
    for(int i=0;i<=x;i++)
      result=x*n;
    cout << "n Power x = " << result;
  }
  else
  {
    cout << "x must be a positive number";
  }
  getch();
  return 0;
}

 

Share.

I'm a full-stack developer, specializing in the PHP, JS, Wordpress, MEAN Stack, MERN Stack & Django. I hold a high standard of quality in everything that I do.

1 Comment

  1. Muhammad Noman on

    #include
    #include
    #include
    using namespace std;
    int main() {
    int x,n,result=1;
    cout<>n;
    cout<>x;

    for(int i=1;i<=x;i++)
    {
    result=n*result;

    }cout<<n<<" ^ "<<x<<" = "<<result;

    getch();
    }

Leave A Reply