1 / 7

Esercizio

Esercizio. Usate il ciclo repeat until (controllo post condizionale) per simulare il prodotto N x M con M somme di N. Esempio: 5 x 3 equivale a fare 5 +5 +5, cioè tre volte la somma di 5. Pseudocodifica. Inizio Chiedi i due numeri da moltiplicare N x M Leggi i due numeri N ed M

Download Presentation

Esercizio

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Esercizio Usate il ciclo repeat until (controllo post condizionale) per simulare il prodotto N x M con M somme di N. Esempio: 5 x 3 equivale a fare 5 +5 +5, cioè tre volte la somma di 5.

  2. Pseudocodifica Inizio Chiedi i due numeri da moltiplicare N x M Leggi i due numeri N ed M Ripeti m volte : Prodotto=prodotto+N Scrivi prodotto Fine.

  3. Pseudocodifica Inizio Chiedi (n,m) Leggi (n,m) Ripeti Prodotto=prodotto+N m=m-1 Finché m=0 Scrivi prodotto Fine.

  4. Diagrammadiflusso inizio Chiedi (n,m) Leggi (n,m) Prodotto=0 Prodotto = prodotto + n m=m-1 M=0 ? Scrivi prodotto fine

  5. Codice dev-pascal • program prodotto; • var m,n,p:integer; • begin • writeln( ‘Inserisci due numeri interi da moltiplicare’ ); • write( ‘il primo? : ‘ ); readln(m); • write( ‘il secondo? : ‘ ); readln(n); • p:=0; • repeat • p:=p+m; {il ciclo effettua n somme} • n:=n-1 {del numero m} • until n=0; • writeln( ‘ Il risultato e’’ : ‘ , p); • readln; • end.

More Related