C program which return power of integer Value using a function (base
power)
Question-> Write a integer
power function which return the power of base
This program return the value of
any integer power the integer value will entered by user for example 52
= 25,53 = 125. Here I used a
function which both value base and exponent.function name is integer_power you
can redefine this function it takes two integer type variable.This program is
only for integer values.
#include<stdio.h>
int integer_power(int x,int y) ; //prototype of function
int main()
{
int base,exponent ;
int final_answer ; //variable
printf("-------Enter the
value of base and exponent---------\n") ;
printf("Enter
value of base-") ;
scanf ( "%d" , &base) ; //fetch base value
from user
printf( "Enter value of exponent-" ) ;
scanf( "%d" , &exponent) ; //fetch exponent value
from user
final_answer = integer_power(base,exponent) ;
printf( "\nyour final answer is %d" ,final_answer) ;
}
int integer_power(int x , int y) //here my function which
return final value
{
int z;
int total=1;
for(z=1 ; z<=y ; z++)
{
total
= x*total ; //return final value
}
return total ;
No comments:
Post a Comment