Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5.  
  6. const char * OPER_NAMES[] = { "x", "sin(x)", "cos(x)", "log(x)", "exp(x)", NULL };
  7.  
  8. double identite(double x)
  9. {
  10. return x;
  11. }
  12.  
  13. double erreur(double x)
  14. {
  15. printf("erreur\n");
  16. return 0;
  17. }
  18.  
  19. double (*OPER_FN [])(double) = { identite, sin, cos, log, exp, erreur };
  20.  
  21. typedef enum ope {
  22. ID , SIN, COS, LOG, EXP, NONE
  23. } OP;
  24.  
  25. int identification(char chaine[])
  26. {
  27. OP operation = ID;
  28. while ( OPER_NAMES[operation] && strcmp(chaine,OPER_NAMES[operation]) )
  29. {
  30. operation++;
  31. }
  32. return operation;
  33. }
  34.  
  35. double evaln(double d, OP operation)
  36. {
  37. double resultat;
  38. switch (operation)
  39. {
  40. case ID:
  41. resultat = d;
  42. break;
  43. case SIN:
  44. resultat = sin(d);
  45. break;
  46. case COS:
  47. resultat = cos(d);
  48. break;
  49. case LOG:
  50. resultat = log(d);
  51. break;
  52. case EXP:
  53. resultat = exp(d);
  54. break;
  55. default:
  56. break;
  57. }
  58. return resultat;
  59. }
  60.  
  61. double evalp(double d, OP operation)
  62. {
  63. return OPER_FN[operation](d);
  64. }
  65.  
  66. void calcul(float a, float b, float d, OP operation)
  67. {
  68. double i;
  69. for (i = a; i <= b; i = i + d )
  70. {
  71. printf("%f\n", evalp(i, operation));
  72. }
  73. }
  74.  
  75.  
  76.  
  77.  
  78. int main()
  79. {
  80. printf("%f\n",evalp(0, COS));
  81. char operation[255];
  82. float a, b, d;
  83. printf("veuillez saisir l'opération\n");
  84. scanf("%s", operation);
  85. OP op = identification(operation);
  86.  
  87. printf("veuillez saisir l'intervalle et le pas\n");
  88. scanf("%f %f %f", &a, &b, &d);
  89.  
  90.  
  91. calcul(a, b, d, op);
  92. return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement