Informatică, întrebare adresată de deniscostin, 8 ani în urmă

1)De realizat cel mai mare dizivor comun cu do-while.
2)De la tastatura se citeste un numar intreg.Sa se realizeze un program care ne-ar afisa suma cifrelor acestui numar.
URGENT!!!!!!!

Răspunsuri la întrebare

Răspuns de ImiPlaceChimia
0

1)

#include <bits/stdc++.h>

using namespace std;

int main() {

   int x, y;

   cin >> x >> y;

   bool gata = false;

   int cmmdc;

   do {

       cmmdc = __gcd(x, y);

       gata = true;

   } while (!gata);

   cout << cmmdc << '\n';

   return 0;

}

2)

#include <bits/stdc++.h>

using namespace std;

int main() {

   string x; cin >> x;

   cout << accumulate(x.begin(), x.end(), 0) - '0' * x.size() << '\n';

   return 0;

}

Alte întrebări interesante