Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <conio.h>
- float puissance(float p,int n){
- float puis = 1.;
- int m = 1;
- while(m <= n){
- puis *= p;
- m++;
- }
- return puis;
- }
- float factorielle(int n){
- float fact = 1.;
- int i = 1;
- while(i <= n){
- fact *= i;
- i++;
- }
- return fact;
- }
- float cos_(float p , int n){
- int m=0;
- float E = 0.00001;
- float cos = 0.0;
- int c = 1;
- do{
- cos =c*(puissance(p,2*m)/factorielle(2*m)) + cos;
- c *= -1;
- m++;
- }while((puissance(p,2*m+2)/factorielle(2*m+2) >= E)/* && (m <= n)*/);
- return cos;
- }
- float sin_(float p,int n){
- float sin = 0.0,E = 0.0001;
- int m = 0, c = 1;
- do{
- sin = c*(puissance(p,2*m + 1)/factorielle(2*m + 1)) +sin;
- c *= -1;
- m++;
- }while((puissance(p,2*m+3)/factorielle(2*m+3) >= E)/* && (m <= n)*/);
- return sin;
- }
- float tan_(float p,int n){
- char s = 'f';
- if(cos_(p,n) == 0){
- printf("La tangente de est n'existe pas!");
- return s;
- }else{
- return (sin_(p,n)/cos_(p,n));
- }
- }
- int main(){
- float x,c,s,t;
- int n;
- printf("Donner un nombre pour calculer son cos ,sin ,tan : ");
- if(scanf("%f",&x) != 1){
- printf("Invalide input");
- return 0;
- }else{
- printf("Donner l'ordre: ");
- do{
- scanf("%d",&n);
- }while(n<0);
- c = cos_(x,n);
- s = sin_(x,n);
- if(tan_(x,n) == 'f'){return 0;}else{
- t = tan_(x,n);
- printf("Le cosinus de %f est: %.10f\nLe sinus de %f est: %.10f\nLa tangente de %f est: %.10f\n",x,c,x,s,x,t);
- }
- getch();
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement