guys. check this code. can you please make it compact?
i mean i am not allowed to use any function but main. i need help.
Code:
#include<stdio.h>
#include<stdlib.h>
#define PI 3.141592653589
#define NUMBER_OF_TERMS 10
double factorial(double x)
{
double ctr, total;
ctr=x;
total=x;
while(ctr>1)
{
ctr--;
total = total * ctr;
}
return total;
}
double power(double x, double y)
{
double ctr, z;
ctr=0;
z = x;
while (ctr<(y-1))
{
ctr++;
x = x * z;
}
return x;
}
double cosine_func(double radians)
{
int ctr, x;
double cosine;
x=0;
ctr=0;
cosine = 0;
while(ctr<NUMBER_OF_TERMS-1)
{
ctr++;
x=x+2;
if(ctr%2 == 0)
{
cosine = cosine - (power(radians, x)/factorial(x));
}
else if(ctr%2 != 0)
{
cosine = cosine + (power(radians, x)/factorial(x));
}
}
return cosine;
}
main()
{
double ctr; // counter
double x; // x value
double radians; // value of x in radians
double cosine; // cosine of x
double cosinetest;// cosine of x
double sine; // sine of x
printf("AGUSTIN_MARK S27\n\n");
printf("x(degrees)\t x(radians)\t\t cos x\t\tsin x\n");
ctr = 0;
x = -185;
while (x<180)
{
ctr++;
x+=5;
radians=x*PI/180.0;
cosine=1-cosine_func(radians);
sine=0;
printf("%.2lf\t\t%.12lf\t\t%.12lf\t\t%.2lf\n", x, radians, cosine, sine);
}
system("pause");
}