1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N (10)
float sommec(int N,char*str){
double sum=0.0;
int i;
if(N==0){
sum=0;
}
if (N==1 && str[i]!='+'||str[i]!='-'){
sum+=atof(*str);}
else{
for(i=0;i<N;i++){
if (str[0]=='+'){
sum += atof(str+1)+sommec(str+2,N-2);
}
if (str[0]=='-'){
sum += atof(str)+sommec(str+2,N-2);
}
sum +=atof(str)+sommec(str+1,N-1)
}
}
return sum ;
}
int main() {
char*str="-10.48+50-10, 04+8-244";
sommec(N,str);
printf("la somme vaut %f",sum);
return 0;
} |
Partager