Explain the following program (What does the program do). #include long int function1(int x,int y) { long int result=1; if(y == 0) return result; result=x*( function1 (x,y-1)); } int main() { int bNum,pwr; long int result; printf("\n\n Function 1:\n"); printf("---------------------------------------------------- \n"); printf(" Input the first value : "); scanf("%d",&bNum); printf(" Input the second value : "); scanf("%d",&pwr); result= function1 (bNum,pwr); //called the function 1 printf(" The value of %d function 1 of %d is : %ld\n\n",bNum,pwr,result); return 0; }
#include <stdio.h>
long int function1(int x,int y) {
long int result=1;
if(y == 0)
return result;
result=x*( function1 (x,y-1));
}
int main() {
int bNum, pwr;
long int result;
printf("\n\n Function 1:\n");
printf("---------------------------------------------------- \n");
printf(" Input the first value : ");
scanf("%d",&bNum);
printf(" Input the second value : ");
scanf("%d",&pwr);
result= function1 (bNum,pwr); //called the function 1
printf(" The value of %d function 1 of %d is : %ld\n\n",bNum,pwr,result);
return 0;
}
The function recursively calculates x in y-th power.
The program asks the user for two integer numbers bNum and pwr, and then, using the function1 raises the first number to a power pwr and prints the result.
Comments
Leave a comment