In: Computer Science
Task 3: a) A second-degree polynomial in x is given by the expression = + + , where a, b, and c are known numbers and a is not equal to 0. Write a C function named polyTwo (a,b,c,x) that computes and returns the value of a second-degree polynomial for any passed values of a, b, c, and x. b) Include the function written in part a in a working program. Make sure your function is called from main() and returns a value to main() correctly. Have main() use a printf statement to display the returned value. Test the function by passing various data to it and verifying the returned value.
C/C+ program
c code snippet:
Text code:
#include<stdio.h>
//function to return the value
int polyTwo(int a,int b,int c,int x)
{
//return the value of a*x^2+b*x+c
return a*x*x+b*x+c;
}
int main()
{
//Initializing t as 5 to test the program for 5
various datas
int t=5;
while(t--)
{
int a,b,c,x;
//taking user input for
a,b,c,x
scanf("%d%d%d%d",&a,&b,&c,&x);
//the returned value of polyTwo
function is stored in answer variable
int answer=polyTwo(a,b,c,x);
//printing the answer
printf("The returned polynomial
value is:%d\n",answer);
}
return 0;
}
output:
Hope the solution is useful and if you have any doubt ,please comment down below.