Thursday 3 October 2013

Calculating power of an integer using C

/* C program to calculate the power of an integer*/
#include<stdio.h>
main()
{
int base, exp;
long int value=1;
printf("Enter base number and exponent respectively: ");
scanf("%d%d", &base, &exp);
while (exp!=0)
{ value*=base; /* value = value*base; */
--exp;
}
printf("Answer = %d", value);

No comments:

Post a Comment