Hi, I just wrote a C program as a university internship which must calculate the cosine of a number through the Taylor series. The problem is that the program compiles perfectly but at the time of executing it it stops right after the second scanf. I have tried to use the ddd debugger but it does not seem to detect the problem. The code is as follows:
#include <stdio.h>
main()
{
float x, cos=0, t;
int n, z, r, exp, aux=0, aux2, aux3;
printf("Introduzca el valor de x(real): ");
scanf("%f%*c", &x);
printf("Introduzca el valor de n(natural): ");
scanf("%d", &n);
while(aux<=n);
{
printf("prueba");
aux3=2*aux;
r=aux3;
exp=2*aux;
t=x;
aux2=2;
if(exp==0)
{
t=1;
}
while(aux2<=exp)
{
t=t*x;
aux++;
}
while(aux3>1)
{
aux3--;
r=r*aux3;
}
if(aux3==0)
r=1;
if(aux%2==0)
{
z=1;
}
else
{
z=-1;
}
cos=cos + (t/r)*z;
aux++;
}
printf("cos(%f) = %f\n", x, cos);
}
I would very much appreciate someone helping me because I have been looking for the problem for a long time and I can not find it.