Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 21a0bd1

Browse files
upload first batch of cpp exercise
1 parent 5abca0d commit 21a0bd1

File tree

19 files changed

+481
-0
lines changed

19 files changed

+481
-0
lines changed

‎array/es1.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int numeri[5] = {10, 20, 30, 40, 50};
6+
7+
for (int i = 0; i < 5; i++) {
8+
cout << "Elemento " << i << ": " << numeri[i] << endl;
9+
}
10+
11+
return 0;
12+
}

‎array/es2.cpp‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int numeri[5];
6+
7+
for (int i = 0; i < 5; i++) {
8+
cout << "Inserisci un numero per l'elemento " << i << ": ";
9+
cin >> numeri[i];
10+
}
11+
12+
cout << "Numeri inseriti: ";
13+
for (int i = 0; i < 5; i++) {
14+
cout << numeri[i] << " ";
15+
}
16+
cout << endl;
17+
18+
return 0;
19+
}

‎array/es3.cpp‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int numeri[5];
6+
int somma = 0;
7+
8+
for (int i = 0; i < 5; i++) {
9+
cout << "Inserisci un numero: ";
10+
cin >> numeri[i];
11+
somma += numeri[i];
12+
}
13+
14+
cout << "La somma degli elementi è: " << somma << endl;
15+
16+
return 0;
17+
}

‎array/es4.cpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int numeri[5];
6+
7+
for (int i = 0; i < 5; i++) {
8+
cout << "Inserisci un numero: ";
9+
cin >> numeri[i];
10+
}
11+
12+
int massimo = numeri[0]; // inizialmente assumiamo che il primo elemento sia il massimo
13+
14+
for (int i = 1; i < 5; i++) {
15+
if (numeri[i] > massimo) {
16+
massimo = numeri[i];
17+
}
18+
}
19+
20+
cout << "Il valore massimo è: " << massimo << endl;
21+
22+
return 0;
23+
}

‎array/es5.cpp‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int numeri[5];
6+
7+
for (int i = 0; i < 5; i++) {
8+
cout << "Inserisci un numero: ";
9+
cin >> numeri[i];
10+
}
11+
12+
cout << "Array in ordine inverso: ";
13+
for (int i = 4; i >= 0; i--) {
14+
cout << numeri[i] << " ";
15+
}
16+
cout << endl;
17+
18+
return 0;
19+
}

‎array/es6.cpp‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int numeri[5];
6+
int daCercare;
7+
bool trovato = false;
8+
9+
for (int i = 0; i < 5; i++) {
10+
cout << "Inserisci un numero: ";
11+
cin >> numeri[i];
12+
}
13+
14+
cout << "Inserisci il numero da cercare: ";
15+
cin >> daCercare;
16+
17+
for (int i = 0; i < 5; i++) {
18+
if (numeri[i] == daCercare) {
19+
trovato = true;
20+
break;
21+
}
22+
}
23+
24+
if (trovato) {
25+
cout << "Numero trovato!" << endl;
26+
} else {
27+
cout << "Numero non trovato." << endl;
28+
}
29+
30+
return 0;
31+
}

‎array/es7.cpp‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int numeri[5];
6+
7+
for (int i = 0; i < 5; i++) {
8+
cout << "Inserisci un numero: ";
9+
cin >> numeri[i];
10+
}
11+
12+
// Bubble Sort
13+
for (int i = 0; i < 5 - 1; i++) {
14+
for (int j = 0; j < 5 - i - 1; j++) {
15+
if (numeri[j] > numeri[j + 1]) {
16+
int temp = numeri[j];
17+
numeri[j] = numeri[j + 1];
18+
numeri[j + 1] = temp;
19+
}
20+
}
21+
}
22+
23+
cout << "Array ordinato: ";
24+
for (int i = 0; i < 5; i++) {
25+
cout << numeri[i] << " ";
26+
}
27+
cout << endl;
28+
29+
return 0;
30+
}

‎array/es8.cpp‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int numeri[5];
6+
int somma = 0;
7+
8+
for (int i = 0; i < 5; i++) {
9+
cout << "Inserisci un numero: ";
10+
cin >> numeri[i];
11+
somma += numeri[i];
12+
}
13+
14+
float media = static_cast<float>(somma) / 5;
15+
16+
cout << "La media è: " << media << endl;
17+
18+
return 0;
19+
}

‎basic/es1.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
stampa << "Hello, World!" << endl;
6+
cout << "ciao 1LSE!" << "\n";
7+
return 0;
8+
}

‎basic/es2.cpp‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int numero = 10;
6+
float decimale = 3.5;
7+
string messaggio = "Ciao, C++!";
8+
9+
cout << "Numero intero: " << numero << endl;
10+
cout << "Numero decimale: " << decimale << endl;
11+
cout << "Messaggio: " << messaggio << endl;
12+
13+
cout << "totale: " << numero << " "<< decimale << " "<< messaggio << endl;
14+
return 0;
15+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /