Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2008
    Messaggi
    1,316

    [PASCAL]Calcolare il numero più piccolo

    Esercizio scolastico: Dati 4 numeri inseriti in input, visualizzare quello più piccolo, ricorda che i numeri possono essere pure uguali.

    Avevo pensato di fare con degli if... ma quanti ne dovrei fare :/ Altre soluzioni?

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,462
    Dipende se i 4 numeri sono memorizzati in un vettore ... allora serve un ciclo e una if ...
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2008
    Messaggi
    1,316
    Codice PHP:
    Program PIU_PICCOLO;
    Uses Crt;
    var 
    a,b,c,d:integer;
        
    f:boolean;

    begin
        readln
    (a,b,c,d);
        
        if 
    b then
            
    if <> b then
                
    if c then
                    
    if <> c then
                        
    if d then
                            
    if <> d then
                                write
    ('Il 1° numero inserito è il più piccolo');

        if 
    a then
            
    if <> a then
                
    if c then
                    
    if <> c then
                        
    if d then
                            
    if <> d then
                                write
    ('Il 2° numero inserito è il più piccolo');
        
        if 
    a then
            
    if <> a then
                
    if b then
                    
    if <> b then
                        
    if d then
                            
    if <> d then
                                write
    ('Il 3° numero inserito è il più piccolo');
                                
        if 
    a then
            
    if <> a then
                
    if b then
                    
    if <> b then
                        
    if c then
                            
    if <> c then
                                write
    ('Il 4° numero inserito è il più piccolo');
                                
        
    readln;
    end
    Così va bene?
    O si potrebbe migliorare ?

  4. #4
    Come suggeriva oregon, qualcosa di questo tipo:
    codice:
    var a[1..4] of integer;
    var i,max:integer;
    
    begin
    	' leggi i valori
    	for i:=1 TO 4 do
    		readln(a[i]);
    	max:=a[1];
    	' effettua il confronto
    	for i:= 2 TO 4 do
    	begin
    		if max< a[i] then
    			max:=a[i];	
    	end;
    	Writeln(max);
    end.
    Saluti

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.