forked from PRG1A23/PRG1A23-Labo3-Exercices-courts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex6.cpp
36 lines (29 loc) · 880 Bytes
/
ex6.cpp
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
34
35
36
#include <iostream>
#include <limits>
using namespace std;
// écrire la fonction multiplier qui permette au programme
// ci dessous de fonction comme dans l'exemple d'utilisation
// suivant :
//
//2 3
//2 * 3 = 6
//543 876
//543 * 876 = 475668
//1234567 8765432
//Le produit de 1234567 et 8765432 depasse la limite du type unsigned
bool multiplier(unsigned& a, unsigned& b, unsigned& r);
int main() {
unsigned a, b, r;
do {
cin >> a >> b;
} while (multiplier(a, b, r) and
cout << a << " * " << b << " = " << r << endl);
cout << "Le produit de " << a << " et " << b << " depasse la limite du type unsigned";
}
bool multiplier(unsigned& a, unsigned& b, unsigned& r){
if((static_cast<unsigned long long>(a) * static_cast<unsigned long long>(b)) >= numeric_limits<unsigned>::max() - 1){
return 0;
}
r = a * b;
return 1;
}