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

Commit

Permalink
add es vecchi: rombo e triangolo
Browse files Browse the repository at this point in the history
  • Loading branch information
mc-cat-tty committed Nov 16, 2021
1 parent 8de1a26 commit c08ceae
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
45 changes: 45 additions & 0 deletions esercitazioni/rombo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <iostream>
#include <cmath>

using namespace std;

int main() {
short unsigned int lb; // lunghezza della base
do {
cout << "Inserisci la lunghezza (intera) del lato: "; cin >> lb;
} while (lb%2 == 0);

short unsigned int lo = (lb-1)/2+1; // lunghezza del lato obliquo (e altezza)
// cout << lo << endl; // tracing

int n_ast; // numero di asterischi
int n_spaces;
for (int i=0; i<lo; i++) {
n_ast = 1 + i*2;
// cout << n_ast << endl; // tracing
n_spaces = (lb - n_ast)/2;
// cout << n_spaces << endl; // tracing
for (int j=0; j<lb; j++) {
if (j>=n_spaces && j<n_spaces+n_ast)
cout << "*";
else
cout << " ";
}
cout << endl;
}
for (int i=lo-2; i>=0; i--) {
n_ast = 1 + i*2;
// cout << n_ast << endl; // tracing
n_spaces = (lb - n_ast)/2;
// cout << n_spaces << endl; // tracing
for (int j=0; j<lb; j++) {
if (j>=n_spaces && j<n_spaces+n_ast)
cout << "*";
else
cout << " ";
}
cout << endl;
}

return 0;
}
32 changes: 32 additions & 0 deletions esercitazioni/triangolo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>
#include <cmath>

using namespace std;

int main() {
short unsigned int lb; // lunghezza della base
do {
cout << "Inserisci la lunghezza (intera) del lato: "; cin >> lb;
} while (lb%2 == 0);

short unsigned int lo = (lb-1)/2+1; // lunghezza del lato obliquo (e altezza)
// cout << lo << endl; // tracing

int n_ast; // numero di asterischi
int n_spaces;
for (int i=0; i<lo; i++) {
n_ast = 1 + i*2;
// cout << n_ast << endl; // tracing
n_spaces = (lb - n_ast)/2;
// cout << n_spaces << endl; // tracing
for (int j=0; j<lb; j++) {
if (j>=n_spaces && j<n_spaces+n_ast)
cout << "*";
else
cout << " ";
}
cout << endl;
}

return 0;
}

0 comments on commit c08ceae

Please sign in to comment.