Search This Blog

Program to Find Power of a Number

This is a c program to calculate power of a given number. The inputs are the number and its exponent (power). For example, if you give m and n, the result is m^n.

#include<stdio.h>
int main()
{
    int m, n, i,p=1;
    printf("Enter the number and its power (exponent)\n");
    scanf("%d%d",&m,&n);
    for( i = 0 ; i < n ; i++ )
        p*=m;
    printf("%d raised to %d is: %d",m,n,p);
}

Output:

Enter the number and its power (exponent) 2 3 2 raised to 3 is: 8

No comments: