Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #pragma hdrstop
  4. #include<stdio.h>
  5. #include<conio.h>
  6. #include<math.h>
  7. //---------------------------------------------------------------------------
  8. double puissance(double a,int b);
  9. int factorielle(int n);
  10. double exponentielle(int exp);
  11. double sinus(double x);
  12. double logarithme(double log);
  13. //---------------------------------------------------------------------------
  14. double puissance (double a,int b)
  15. {
  16. double c;
  17. for (c=1;b>=1;b--)
  18. {
  19. c = c * a ;
  20. }
  21. return c;
  22. }
  23. //---------------------------------------------------------------------------
  24. int factorielle(int n)
  25. {
  26. int i; /*compteur de boucle*/
  27. for(i=n-1 ; i>=1 ;i--)
  28. {
  29. n=n*i;
  30. }
  31. return n;
  32. }
  33. //---------------------------------------------------------------------------
  34. double exponentielle(int exp)
  35. {
  36. int y;
  37. double a = 0;
  38. for(y=1;y<=11;y++)
  39. {
  40. a = a + (puissance(exp,y)/(double)factorielle(y) );
  41. }
  42. return 1 + a;
  43. }
  44. //---------------------------------------------------------------------------
  45. double sinus(double s)
  46. {
  47. int v;
  48. double b = 0;
  49. int signe = -1;
  50. for(v=3;v<=11;v=v+2)
  51. {
  52. b = b - (puissance(s,v)/(double)factorielle(v) * signe);
  53. signe = signe * (-1);
  54. }
  55. return s - b;
  56. }
  57. //---------------------------------------------------------------------------
  58. double logarithme(double log)
  59. {
  60. int c;
  61. double z = (log-1)/(log+1);
  62. double a = 0;
  63. for(c=1;c<=11;c =c+2)
  64. {
  65. a = a + (puissance(z,c))/c;
  66. }
  67. return 2 * a;
  68. }
  69. //---------------------------------------------------------------------------
  70. void main()/*Programme Principal*/
  71. {
  72. int a,b,n,reponse;
  73. double y,resultat,x,rep,q,res,w,calc;
  74. char choix;
  75. printf("Entrer 1 pour la fonction puissance\n");
  76. printf("Entrer 2 pour la fonction factorielle\n");
  77. printf("Entrer 3 pour la fonction exponentielle\n");
  78. printf("Entrer 4 pour la fonction sinus\n");
  79. printf("Entrer 5 pour la fonction logarythme\n");
  80. scanf("%c",&choix);
  81. flushall();
  82. switch(choix)
  83. {
  84. case'1':/*Fonction Puissance*/
  85. printf("Entrer un nombre:\n");
  86. scanf("%lf",&y);
  87. printf("Entrer sa puissance:\n");
  88. scanf("%d",&b);
  89. resultat = puissance(y,b);
  90. printf("Voici son resultat:%lf\n",resultat);
  91. break;
  92. case'2':/*Fonction Factorielle*/
  93. printf("Entrer un nombre:\n");
  94. scanf("%d",&n);
  95. reponse = factorielle(n);
  96. printf("Voici son resultat:%d\n",reponse);
  97. break;
  98. case'3':/*Fonction Exponentielle*/
  99. printf("Entrer un nombre:\n");
  100. scanf("%lf",&x);
  101. rep = exponentielle(x);
  102. printf("Voici son resultat:%lf\n",rep);
  103. break;
  104. case'4':/*Fonction Sinus*/
  105. printf("Entrer un nombre:\n");
  106. scanf("%lf",&q);
  107. res = sinus(q);
  108. printf("Voici son resultat:%lf\n",res);
  109. break;
  110. case'5':/*Fonction Logarithme Népérien*/
  111. printf("Entrer un nombre:\n");
  112. scanf("%lf",&w);
  113. calc = logarithme(w);
  114. printf("Voici son resultat:%lf\n",calc);
  115. break;
  116. }
  117. getch();
  118. }
  119. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement