PLAY WITH CODING

Home Basic Program If & Else Loops Conversion Pattern logo

Basic C Program

Program to Calculate power of a number

Input - Output

Input
Enter a number : 3

Enter the expontial : 4

Output
Result = 81

Algorithm

Step 1: START

Step 2: Take a number as input.

Step 3: calculate power i.e pow(num).

Step 4: Print result

Step 5: END

CODE


/* Power of a number */

#include <stdio.h>
#include <math.h>
int main()
{
      int base,expontial,result;
      printf("Enter the base : ");
      scanf("%d",&base);
      printf("Enter the expontial : ");
      scanf("%d",&expontial);
      result=pow(base,expontial);
      printf("results = %d\n",result);
    return 0;
}


/* Power of a number */

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
      int base,expontial,result;
      cout<<"Enter the base : ";
      cin>>base;
      cout<<"Enter the expontial : ";
      cin>>expontial;
      result=pow(base,expontial);
      cout<<"results = "<<result;
    return 0;
}

OutPut

Enter a number : 3
Enter the expontial : 4

Result = 81