C language Create a program that prompts the user for two integer numbers. The p
ID: 3797126 • Letter: C
Question
C language
Create a program that prompts the user for two integer numbers. The program must be written in a way where the functions are written to perform its own unique duty.
Function 1 protoype: int customFunction(int a, int b)
This function will take two integer numbers and will implement the following fuction. (Can't use power fuction from math.h)
F(x) = a^2 + 2ab + b^2
Function 2 protoype: int baseToThePower(int a, int b)
This function will take an integer number (int b) and it will be raised to the power of "a". The result will be returned to the main function. (Not allowed to use the power function from math.h)
Function 3 prototype: should implement a print function that prints result as shown below:
Name: Jack
Please enter the first number (a): 4
Please enter the second number (b): 10
Followig results:
(1) The result of implementing the customFunction is : 196
(2) The result of raising 10 to the power of 4 is: 10000
Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
int main()
{
//declare function prototype
int customFunction(int a, int b);
int baseToThePower(int a, int b);
void print(int first_function, int second_function,int b);
int ret1, ret2;
int a, b;
printf("Name: Jack ");
printf("Please enter the first number (a): ");
scanf("%d", &a);
printf("Please enter the second number (b): ");
scanf("%d", &b);
//call function customFunction
ret1 = customFunction(a, b);
//call function baseToThePower
ret2 = baseToThePower(a, b);
//call print function to print result
print(ret1, ret2,b);
}
int baseToThePower(int a, int b)
{
int i,prod = 1;
for (i = 0; i < a; i++)
{
prod *= b;
}
return prod;
}
int customFunction(int a, int b)
{
//function F(x) = a^2 + 2ab + b^2
int sum ;
sum = baseToThePower(2, a) + 2 * a*b + baseToThePower(2, b);
return sum;
}
void print(int result1, int result2,int b)
{
printf("The result of implementing the customFunction is : %d ", result1);
printf("The result of raising %d to the power of 4 is: %d ", b,result2);
}
-------------------------------------------------------------------------
//output same as posted ie
Name: Jack
Please enter the first number (a): 4
Please enter the second number (b): 10
The result of implementing the customFunction is : 196
The result of raising 10 to the power of 4 is: 10000
//output2
Name: Jack
Please enter the first number (a): 3 10
Please enter the second number (b): The result of implementing the customFunctio
n is : 169
The result of raising 10 to the power of 4 is: 1000
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.