Answer to Question #175910 in C for Rania

Question #175910

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; }


1
Expert's answer
2021-03-27T15:35:17-0400
#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.



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS