Wednesday, March 23, 2011

A power B calculation

# include "stdio.h"

double what( double , int );
int main()
{
int nNumber1,nNumber2;
int nLoop1,nLoop2;

printf("Enter the two number you want to display\n");
scanf("%d%d",&nNumber1,&nNumber2);

//Type casting from the double to integer

printf("A power B : %d \n",(int)what(nNumber1,nNumber2));

return 0;
}

double what( double z, int y)
{
double answer = 1;

while( y > 0 )
{
if( y%2 == 1)
answer = answer * z;
y=y/2;
z=z*z;
}
return answer;
}

OUTPUT:

Enter the two number you want to display
10 3
A power B : 1000
Press any key to continue . . .

No comments:

Post a Comment