Accueil     Soft. MacOSX     Soft. MacOS/PC     PHP     Python     ROMS GBA     TP d'info     DBZ-GT     Martingales     Galeries     Liens     @  

TP4 - Exo 1.1

/*
TP4 29/10/02
http://www.Software-DS.com

*/
#include <stdio.h>
#include "pile.h"

PILE opd,opt;

int evaluer(int y,int x,int op);
void horner(char E[100],int *x,int *i);
void traiter(char E[100],int *i);

int evaluer(int y,int x,int operat) {
switch(operat) {
case 1 :
return(x+y);
break;
case 2 :
return(x-y);
break;
case 3 :
return(x*y);
break;
case 4 :
if (x==0){
printf("Fatal Error, division par zero impossible !\n");
return(0);
}
else
return(x/y);

default: /* Facultatif */
printf("Operateur inconnu");
return(0);
}
}

void horner(char E[100],int *x,int *i) {
*x=0;
while (((E[*i])<='9') && ((E[*i])>='0')) {
(*x)*=10;
(*x)+=E[*i]-'0';
(*i)++;
}
(*i)--;
}

void traiter(char E[100],int *i){
int x,y;

switch(E[*i]){
case '(' :
break;

case ' ' :
break;

case '0' :
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
case '9' :
horner(E,&x,i);
opd=empiler(opd,x);
break;

case '+' :
opt=empiler(opt,1);
break;

case '-' :
opt=empiler(opt,2);
break;

case '*' :
opt=empiler(opt,3);
break;

case '/' :
opt=empiler(opt,4);
break;

case ')' :
x=sommet(opd);
opd=depiler(opd);
y=sommet(opd);
opd=depiler(opd);
opd=empiler(opd,evaluer(x,y,sommet(opt)));
opt=depiler(opt);
break;

default :
printf("Caractere non gerer ! Probleme ! ERRROR !\n");
}
}
/* MAIN */
int main(void) {
char E[100];
int i=0,j;
/* INITIALISATION */
opd=creer_pile(opd);
opt=creer_pile(opt);
/* SAISIE */
printf("saisirl'expression\n");
scanf("%s",&E);

/* BOUCLE PRINCIPALE */
while (E[i]!='=') {
traiter(E,&i);
i++;
}
printf("\nResultat = %d\n",sommet(opd));
printf("\n©2002 All Rights Reserved to http://www.Software-DS.com\n\n");
return(0);
/* ©2002 All Rights Reserved to Didier STRAUS http://www.Software-DS.com */
}




Haut de la page - Page précédente - Page générée en 0.00178 sec.
Recherche personnalisée
 

1843767 visiteurs.   ©2001-2023 All Rights Reserved to Software-DS.com
Made with a mac  
Confidentialité