Enunciado
Leer una sucesión de n números reales (n>=0) y verificar que están ordenados de menor a mayor.
Código
Python
def main():
print( "Cantidad de números/amount of numbers: " )
n = int( input() )
if n>0:
print( "\nLa entrada de datos se interrumpe " )
print( "al detectarse la primera falla" )
print( "Data entry is interrupted ", end="" )
print( "when the first fault is detected" )
b = 1
print( "\nIngresar los números/", end="" )
print( "Enter the numbers:" )
a1 = int( input() )
n -= 1
while n>0 and b==1:
a2 = int( input() )
n -= 1
if a1<=a2: a1 = a2
else: b = 0
if b==0:
print( "\nSucesión no ordenada/", end="" )
print( "Unordered succession" )
else:
print( "\nSucesión ordenada/", end="" )
print( "Ordered succession" )
else:
print( "\nNo hay números/There are no numbers")
input( "Presionar/Press Enter to exist " )
main()
C++
#include <iostream>
using namespace std ;
#include <conio.h>
int main()
{
int n, b ;
float a1, a2 ;
cout << "Cantidad de n£meros/amount of numbers: " ;
cin >> n ;
if ( n>0 )
{
cout << "La entrada de datos se interrumpe" ;
cout << " al detectarse la primera falla" ;
cout << endl ;
cout << "Data entry is interrupted when" ;
cout << " the first fault is detected" ;
cout << endl ;
b=1 ;
cout << endl << "Ingresar los n£meros/" ;
cout << "Enter the numbers: " << endl ;
cin >> a1 ;
n-- ;
while ( n>0 && b==1 )
{
cin >> a2 ;
n-- ;
if ( a1<=a2 ) a1=a2 ;
else b=0 ;
}
if ( b==0 )
{
cout << endl << "Sucesi¢n no ordenada/" ;
cout << "Unordered succession" << endl ;
}
else
{
cout << endl << "Sucesi¢n ordenada/" ;
cout << "Ordered succession" << endl ;
}
}
else
{
cout << endl << "No hay n£meros/" ;
cout << "There are no numbers " << endl ;
}
cout << "Presionar/Press Enter to exit " ;
getch() ;
return 0 ;
}
Pascal
Program Problema8_10 ;
var
n : integer ;
b : 0..1 ;
a1, a2 : real ;
begin
write( 'Cantidad de n£meros/amount of numbers: ' ) ;
readln( n ) ;
writeln ;
if n>0
then
begin
write( 'La entrada de datos se interrumpe ' ) ;
writeln( 'al detectarse la primera falla' ) ;
write( 'Data entry is interrupted when ' ) ;
writeln('the first fault is detected' ) ;
writeln ;
b := 1 ;
write( 'Ingresar los n£meros/' ) ;
writeln( 'Enter the numbers: ' ) ;
readln( a1 ) ;
n := n-1 ;
while (n>0) and (b=1) do
begin
readln( a2 ) ;
n := n-1 ;
if a1<=a2 then a1 := a2 else b := 0 ;
end ;
if b=0
then
begin
write( 'Sucesi¢n no ordenada/' ) ;
writeln( 'Unordered succession' ) ;
end
else
begin
write( 'Sucesi¢n ordenada/' ) ;
writeln( 'Ordered succession' ) ;
end
end
else
begin
write( 'No hay n£meros/' ) ;
writeln( 'There are no numbers' ) ;
end ;
writeln( 'Presionar/Press Enter to exit' ) ;
readln ;
end.
Diagramas


