tags: C# Brush Question Record [Beginner] c language algorithm
#include<stdio.h>
#include <math.h>
//First define a factorial function
double fac(double n){
double f=0;
if(n == 1 || n==0)
f =1;
else
f = fac(n-1)*n;
return f;
}
//An exponential function (power)
double kvat(double n,double ci){
double chengf=1;
for (int i=1; i<=ci; i++) {
chengf = chengf*n;
}
return chengf;
}
double sinus(double x){
int z =-1;
int j =1;
double sin=x;
for (j =3;fabs( kvat(x,j)/fac(j) )>0.001 ; j+=2) {
// printf("%lf\n",kvat(x, j));
sin =sin + z*(kvat(x,j)/fac(j));
z = -z;
}
return sin;
}
int main(){
double jd,hudu;
scanf("%lf",&jd);
hudu = (jd*M_PI)/180;//M_PI here is pi pai in math library
printf( "%.3lf",sinus(hudu));
return 0;
}
Today, a friend asked me, I wrote it, it is very simple, it is involved in some basic knowledge. The more you learn, the more you can't forget....
Calculate the cosine value from 0 to 359 degrees, and calculate the average need to calculate the size of the last n of the result, n starts from 0. As n increases, each item is also a very expensive ...
Record: strlen () function and printf ("% s", str) are all encountered with '\ 0' ending. And the parameters inside the printf () are from right to left. The result of running is 2,1 B,A...
The blog is "Ubuntu related》The third part of the series of blogs. This series of blogs mainly records the installation of various software or libraries on Ubuntu, so as to facilitate the quick r...
Source of the topic: Dagong Mu Lessonlink OF: Caleb Sung Topic requirements Calculate the solution of ax^2+bx+c=0, use three functions to calculate the root when delta is greater than, equal to, and l...
COSX SINX Taylor expansion C ++ Common Taylor launches: The results are as follows: think:...
The classification of functions in C language is generally two kinds of library functions and custom functions. First look at some examples of library functions: 1. In our C language learning process,...
Hello.txt file creation, and fill it writes "Hello, Software Weekly";...
Task code: modf separates the integer part and the decimal part of a number: round rounds the decimal part to the integer part: Implementation: Knowledge summary: The library function is the function ...