Advertisement
lineoff

fcttrigono

Nov 19th, 2014
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <conio.h>
  3. float puissance(float p,int n){
  4.     float puis = 1.;
  5.     int m = 1;
  6.     while(m <= n){
  7.         puis *= p;
  8.         m++;
  9.         }
  10.     return puis;
  11.     }
  12. float factorielle(int n){
  13.     float fact = 1.;
  14.     int i = 1;
  15.         while(i <= n){
  16.             fact *= i;
  17.             i++;
  18.             }
  19.         return fact;
  20.         }
  21.  
  22. float cos_(float p , int n){
  23.     int m=0;
  24.     float E = 0.00001;
  25.     float cos = 0.0;
  26.     int c = 1;
  27.     do{
  28.             cos =c*(puissance(p,2*m)/factorielle(2*m)) + cos;
  29.             c *= -1;
  30.             m++;
  31.         }while((puissance(p,2*m+2)/factorielle(2*m+2) >= E)/* && (m <= n)*/);
  32.     return cos;
  33.     }
  34. float sin_(float p,int n){
  35.     float sin = 0.0,E = 0.0001;
  36.     int m = 0, c = 1;
  37.     do{
  38.             sin = c*(puissance(p,2*m + 1)/factorielle(2*m + 1)) +sin;
  39.             c *= -1;
  40.             m++;
  41.         }while((puissance(p,2*m+3)/factorielle(2*m+3) >= E)/* && (m <= n)*/);
  42.     return sin;
  43.     }
  44. float tan_(float p,int n){
  45.     char s = 'f';
  46.     if(cos_(p,n) == 0){
  47.         printf("La tangente de  est n'existe pas!");
  48.         return s;
  49.         }else{
  50.             return (sin_(p,n)/cos_(p,n));
  51.             }
  52.     }
  53. int main(){
  54.     float x,c,s,t;
  55.     int n;
  56.     printf("Donner un nombre pour calculer son cos ,sin ,tan : ");
  57.     if(scanf("%f",&x) != 1){
  58.         printf("Invalide input");
  59.         return 0;
  60.         }else{
  61.             printf("Donner l'ordre: ");
  62.     do{
  63.         scanf("%d",&n);
  64.         }while(n<0);
  65.     c = cos_(x,n);
  66.     s = sin_(x,n);
  67.     if(tan_(x,n) == 'f'){return 0;}else{
  68.     t = tan_(x,n);
  69.     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);
  70.     }
  71.     getch();
  72.     return 0;
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement