Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
aggiunta esercizi su iterazioni
Browse files Browse the repository at this point in the history
  • Loading branch information
mc-cat-tty committed Oct 21, 2021
1 parent 9c6ed65 commit c1884ad
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
esercutazioni/*.out
esercitazioni/*.out

Binary file modified esercitazioni/a.out
Binary file not shown.
13 changes: 13 additions & 0 deletions esercitazioni/div_successiva.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>

using namespace std;

int main() {
int n;
cin >> n;
do {
cout << n << " ";
n /= 10;
} while (n>0);
cout << endl;
}
22 changes: 22 additions & 0 deletions esercitazioni/molt_come_somma.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <iostream>

using namespace std;

int main() {
int a, b;
cin >> a >> b;

int res = 0;
if (b<a) { // ottimizzazione per minimizzare il numero di iterazioni
a += b;
b = a-b;
a -= b;
}
for (int i=0; i<a; i++) { // prodotto come sequenza di somme di due numeri
res += b;
}
cout << a << " iterazioni" << endl;

cout << a << " * " << b << " = " << res << endl;
return 0;
}
13 changes: 13 additions & 0 deletions esercitazioni/numero_contrario.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>

using namespace std;

int main() {
int n;
cin >> n;
while (n>0) {
cout << n%10;
n /= 10;
}
cout << endl;
}

0 comments on commit c1884ad

Please sign in to comment.