ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.
-
Upload
nunziatella-festa -
Category
Documents
-
view
212 -
download
0
Transcript of ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.
![Page 1: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/1.jpg)
ESERCITAZIONE N. 5
ESERCIZIO N. 1
Autore: Biagio Brattoli S161894 I Corso
![Page 2: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/2.jpg)
IL PROBLEMA CHIEDE DI STAMPARE UN NUMERO DISPARI DI ASTERISCHI NELLA PRIMA RIGA, DUE IN MENO NELLA SECONDA E COSì FINO A CHE NON NE RIMANE SOLO UNA
********* ******* ***** *** *
![Page 3: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/3.jpg)
ALLORA:
Leggo num_asterischi
While (num_asterischi > 0)
stampa_una_riga
decremento num_asterischi di 2
Ora ci concentriamo su stampa_una_riga
![Page 4: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/4.jpg)
AD OGNI RIGA DEVO STAMPARE
UN CERTO NUMERI DI SPAZI,
UN NUMERO DI ASTERISCHI PARI Anum_asterischi
num_asterischi DIMINUISCE DI 2 AD OGNI GIRO
![Page 5: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/5.jpg)
IL NUMERO DI SPAZI È ZERO LA PRIMA RIGA, 1 LA SECONDA, 2 E COSì VIA…
leggo num_ast num_spazi = 0 while (num_ast > 0) stampa un numero di blank pari a
num_spazi
stampa un numero di asterischi pari a num_ast
vai_a_capo
incrementa di 1 num_spazi decrementa di 2 num_asterischi
![Page 6: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/6.jpg)
FINITA LA PARTE PRINCIPALE
DELL’ALGORITMO INSERISCO I
CONTROLLI E SPECIFICO QUALE
CICLO UTILIZZARE
![Page 7: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/7.jpg)
leggo num_ast if(num_ast e' dispari) num_spazi = 0 while (num_ast > 0) contatore = 0 while(contatore < num_spazi) stampa_1_spazio contatore = 0 while(contatore < num_ast) stampa_1_asterisco vai_a_capo incrementa di 1 num_spazi decrementa di 2 num_ast else stampa "errore"
![Page 8: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/8.jpg)
L’ULTIMO PASSO è QUELLO
DI TRADURRE IN LINGUAGGIO C
![Page 9: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/9.jpg)
#include <stdio.h>#include <stdlib.h>
main(){int num_ast, spazi, contatore;system ("CLS");
scanf ("%d", &num_ast);
if ((num_ast % 2) == 1) /*se dispari*/{spazi = 0;while (num_ast > 0) /*per le righe*/
{contatore = 0;
while (contatore < spazi){printf (" ");contatore++;}
![Page 10: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/10.jpg)
contatore = 0;while (contatore < num_ast) /*stampa gli asterischi*/
{printf ("*");contatore++;}
printf ("\n");spazi = spazi +1;num_ast = num_ast -2;
}
}else
printf ("Numero non dispari");
system ("PAUSE");}
![Page 11: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/11.jpg)
IN ALTERNATIVA POSSIAMO
UTILIZZARE I CICLI FOR
![Page 12: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/12.jpg)
#include <stdio.h>#include <stdlib.h>
main(){int num_ast, N,spazi, contatore;system ("CLS");
scanf ("%d", &num_ast);
if ((num_ast % 2) == 1) /*se dispari*/{spazi = 0;for (N = num_ast; N > 0; N = N - 2) /*per le righe*/
{for (contatore = 0; contatore < spazi; contatore++)
printf (" ");
![Page 13: ESERCITAZIONE N. 5 ESERCIZIO N. 1 Autore: Biagio Brattoli S161894 I Corso.](https://reader036.fdocumenti.com/reader036/viewer/2022082919/5542eb4e497959361e8bc95f/html5/thumbnails/13.jpg)
for (contatore = 0; contatore < N; contatore++) printf ("*");
printf ("\n");spazi = spazi + 1;
}
}else
printf ("Numero non dispari");
system ("PAUSE");}