Hàm tính sinx, cosx, e^x, lnx ppt

2 561 2
Hàm tính sinx, cosx, e^x, lnx ppt

Đang tải... (xem toàn văn)

Thông tin tài liệu

Hàm tính sinx, cosx, e^x,lnx [CODE="hàm tính sinx, cosx,e^x,lnxx"]#include <stdio.h> #include <conio.h> #include <math.h> int menu() { int c; printf("\n Menu \n"); printf("\n1. Tinh e^x = 1 + x/1! + x^2/2! + + x^n/n! + \n"); printf("\n2. Tinh sin(x) = x - x^3/3! + x^5/5! + + (-1)^n*x^(2n+1)/(2n+1)! + \n"); printf("\n3. Tinh cos(x) = 1 - x^2/2! + x^4/4! + (-1)^n*x^2n/(2n)! + \n"); printf("\n4. Tinh l(x) = (x-1)-(x-1)^2/2 + (x-1)^3/3 +(-1)^n*(x-1)^(n+1)/(n+1) + \n"); printf("\n0. Thoat"); printf("\n\n "); printf("\nChon muc : "); do { c = getch(); }while (c>'4'||c<'0'); putc(c, stdout) ; return c - '0'; } void emux() { float x,e,S,gt; int i; printf("\nNhap vao so thuc x = "); scanf("%f",&x); printf("\nNhap vao sai so epsilon = "); scanf("%f",&e); i=1; S=1; gt=1; while (fabs(pow(x,i)/gt) >= e) { S=S+pow(x,i)/gt; i++; gt=gt*i; } printf("\n Tong S = %f",S); getch(); } void sinx() { float x, s, eps, gt, t; int i, dau; printf("\nNhap so thuc x = "); scanf("%f",&x); printf("\nNhap vao sai so epsilon = "); scanf("%f",&eps); s=0.0; gt=1.0; i=0; dau=1; while (fabs(pow(x,2*i+1)/gt) >= eps) { s = s + dau*pow(x,(2*i+1))/gt; i++; gt = gt*(2*i)*(2*i+1); dau=-dau; } printf("\nTong S = %f", s); getch(); } void cosx() { float x,e,S,gt,radian; int i; printf("\nNhap gia tri bang do cho x = "); scanf("%f",&x); printf("\nNhap vao sai so epsilon = "); scanf("%f",&e); radian=x*M_PI/180; i=0; S=0; gt=1; while (fabs(pow(radian,i)/gt) >= e) { S=S+pow(-1,i/2)*pow(radian,i)/gt; i += 2; gt=gt*(i-1)*i; } printf("\n Tong S = %f",S); getch(); } void lnx() { float x, X, s, eps; int i, dau; printf("\nNhap so thuc x = "); scanf("%f",&x); printf("\nNhap vao sai so epsilon = "); scanf("%f",&eps); X=x-1; s=0; i=1; dau=1; while (fabs(pow(X,i)/i) >= eps) { s = s +dau*pow(X,i)/i; i++; dau=-dau; } printf("\n Tong S = %f",s); getch(); } void main() { int chon; do { chon=menu(); switch (chon) { case 1 : emux(); break; case 2 : sinx(); break; case 3 : cosx(); break; case 4 : lnx(); break; } } while (chon!=0); }[/code] . Hàm tính sinx, cosx, e^x ,lnx [CODE=" ;hàm tính sinx, cosx,e^x,lnxx"]#include <stdio.h> #include <conio.h> #include. e) { S=S+pow(-1,i/2)*pow(radian,i)/gt; i += 2; gt=gt*(i-1)*i; } printf(" Tong S = %f",S); getch(); } void lnx( ) { float x, X, s, eps; int i, dau; printf(" Nhap so thuc x = "); scanf("%f",&x); printf(" Nhap. chon; do { chon=menu(); switch (chon) { case 1 : emux(); break; case 2 : sinx(); break; case 3 : cosx(); break; case 4 : lnx( ); break; } } while (chon!=0); }[/code]

Ngày đăng: 06/07/2014, 06:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan