I don't know whether it's Ok or not)

asked Dec 9, 2020
closed Dec 11, 2020

Good evening!
I'm learning how to create functions.
This is my code. I don't know if I wrote the arcsinus formula right.  I underlined it for you. Thanks in advance

#include <stdio.h>
#include <math.h>
float arcsinus(float);
int main()
{
float z, y, Q, k;
printf("Уведіть Z\t");
scanf("%f", &z);
printf("\nУведіть Y\t");
scanf("%f", &y);
if((z>1||z<-1)||(y>1)||(y<-1))
printf("\nУведіть інші значення");
else if(((z>-1)&&(z<1))&&((y>-1)&&(y<1))){
Q=(2+arcsinus(z))/(5-fabs(arcsinus(y)*arcsinus(y)-arcsinus(z)));
printf("\nQ=%f",Q);
}
return 0;
}
float arcsinus(float X){
float sum=X;
for(float n=1;n<12;n++)
sum+=(2*n-1)*pow(X,(2*n+1))/(2*n)*(2*n+1);
return sum;
}

closed with the note: I already know why

+1 vote
answered Dec 9, 2020 by (230 points)

Hi there.

The program runs and compiles fine, could you state some test variables and their expected outcome please?

From what I gather, z and y must be within the range of -1 to +1 to give the resultant Q, else the message

"Уведіть інші значення" is displayed, which I assume means 'out of range'.

commented Dec 11, 2020 by (930 points)
Yes the program runs fine. I've already solved the problem. Thanks for attention!
+1 vote
answered Dec 10, 2020 by (6,240 points)
edited Dec 10, 2020 by LiOS
Do you mean arcsin formula? Searching arcsinus formula recommends arcsin. If so, include the math.h header file and use the asin() function.

I'm not too sure on the official formula, but if you're not allowed to use pre-built functions, you could perhaps input a number and see whether your formula and the asin() function result in the same answer.

https://www.tutorialspoint.com/c_standard_library/c_function_asin.htm
commented Dec 10, 2020 by (930 points)
I know that I can add the math.h library to use the asin function but I'm trying to creat my own function.
commented Dec 11, 2020 by (6,240 points)
If the asin() function is what you want but want to re-create it yourself in a function... you could compare the answer of using the asin function vs your code. If the answer isn't the same, your function isn't correct.