Menu

Thursday, 15 November 2012

Write a function power(a,b) to calculate value of ’ a’ raised to’ b’



#include<stdio.h>
int power(int a,int b);
main()
{
int no1,no2,result;
printf("Enter two numbers for base and exponent: ");
scanf("%d %d",&no1,&no2);

result=power(no1,no2);
printf("\nThe Result of %d^%d is : %d",no1,no2,result);
}
int power(int x,int y)
{
int val,i;
val=1;
for(i=1;i<=y;i++)
{
val=val*x;
}
return val;
}

OUTPUT:

Entr two numbers fo base and exponent: 8
9

The Result of 8^9 is : 0