}
int doSubstraction(int val1, int val2) {
- return val1 - val2;
+ return val1 - val2;
}
int doMultiplication(int val1, int val2) {
int doPuissance(int base, int expo) {
int power = 1;
for (int iter = 0; iter < expo; iter++) {
- power *= base ;
+ power *= base;
}
return power;
}
int doPuissanceSmart(int base, int expo) {
int power;
if (expo == 1) {
- power = base;
+ power = base;
} else if (expo % 2 == 0) {
- power = doPuissanceSmart(base*base, expo/2);
+ power = doPuissanceSmart(base*base, expo/2);
} else {
power = base*doPuissanceSmart(base*base,(expo-1)/2);
}
if (expo % 2 == 0) {
expo /= 2;
} else {
- power *= base;
- expo = (expo - 1) / 2;
+ power *= base;
+ expo = (expo - 1) / 2;
}
base *= base;
}
int op_result;
switch (selection) {
case 1:
- op_result = doAddition(val1, val2);
+ op_result = doAddition(val1, val2);
break;
case 2:
- op_result = doSubstraction(val1, val2);
+ op_result = doSubstraction(val1, val2);
break;
case 3:
- op_result = doMultiplication(val1, val2);
+ op_result = doMultiplication(val1, val2);
break;
case 4:
- op_result = doDivision(val1, val2);
+ op_result = doDivision(val1, val2);
break;
case 5:
op_result = doPuissanceSmartIter(val1, val2);
} */
void promptValue(const char* invite, int* value) {
- puts(invite);
+ puts(invite);
scanf("%d", value);
}
int choiceresult, value1, value2, result;
for (;;) {
choiceresult = promptUserChoice();
- if (choiceresult == 6) break;
+ if (choiceresult == 6) break;
promptBothValues(&value1, &value2);
result = doOperation(choiceresult, value1, value2);
printf("Le resultat est %d\n", result);
int promptValue(const char* invite) {
int value = 0;
- puts(invite);
+ puts(invite);
scanf("%d", &value);
return value;
}
}
int doSubstraction(int val1, int val2) {
- return val1 - val2;
+ return val1 - val2;
}
int doMultiplication(int val1, int val2) {
int doPuissance(int base, int expo) {
int power;
if ( expo == 1) {
- power = base;
+ power = base;
} else if ( expo % 2 == 0 ) {
- power = doPuissance(base*base, expo/2);
+ power = doPuissance(base*base, expo/2);
} else {
power = base*doPuissance(base*base,(expo-1)/2);
}
break;
default:
puts("Faire un choix compris entre 1 et 6");
- }
+ }
return op_result;
}
int main() {
int choice = promptOperation();
int value1 = promptValue("Veuillez saisir une valeur entiere initiale ?");
- int value2 = 0, result = 0;
+ int value2 = 0, result = 0;
bool first_loop = true;
-
+
for (;;) {
if (choice == 6) break;
if (first_loop) {
} else {
value2 = promptValue("Veuillez saisir la prochaine valeur entiere avec laquelle l'operation sera effectuee sur l'ancien resultat ?");
if (value2 == 0) break;
- result = doOperation(choice, result, value2);
+ result = doOperation(choice, result, value2);
}
printf("Le resultat de l'operation choisie est %d\n\n", result);
}