Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- const char * OPER_NAMES[] = { "x", "sin(x)", "cos(x)", "log(x)", "exp(x)", NULL };
- double identite(double x)
- {
- return x;
- }
- double erreur(double x)
- {
- printf("erreur\n");
- return 0;
- }
- double (*OPER_FN [])(double) = { identite, sin, cos, log, exp, erreur };
- typedef enum ope {
- ID , SIN, COS, LOG, EXP, NONE
- } OP;
- int identification(char chaine[])
- {
- OP operation = ID;
- while ( OPER_NAMES[operation] && strcmp(chaine,OPER_NAMES[operation]) )
- {
- operation++;
- }
- return operation;
- }
- double evaln(double d, OP operation)
- {
- double resultat;
- switch (operation)
- {
- case ID:
- resultat = d;
- break;
- case SIN:
- resultat = sin(d);
- break;
- case COS:
- resultat = cos(d);
- break;
- case LOG:
- resultat = log(d);
- break;
- case EXP:
- resultat = exp(d);
- break;
- default:
- break;
- }
- return resultat;
- }
- double evalp(double d, OP operation)
- {
- return OPER_FN[operation](d);
- }
- void calcul(float a, float b, float d, OP operation)
- {
- double i;
- for (i = a; i <= b; i = i + d )
- {
- printf("%f\n", evalp(i, operation));
- }
- }
- int main()
- {
- printf("%f\n",evalp(0, COS));
- char operation[255];
- float a, b, d;
- printf("veuillez saisir l'opération\n");
- scanf("%s", operation);
- OP op = identification(operation);
- printf("veuillez saisir l'intervalle et le pas\n");
- scanf("%f %f %f", &a, &b, &d);
- calcul(a, b, d, op);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement