Advertisement
Abelsor

Mayor Numero

Mar 20th, 2023
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include<iostream>
  2. #include<ctime>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int limite_inferior = 0;
  9.     int limite_superior = 100;
  10.     float n;
  11.    
  12.    
  13.     // validar numero
  14.    
  15.     do{
  16.         cout<<"Ingrese un numero entero y positivo: ";
  17.         cin>>n;
  18.     }
  19.     while(int(n)!=n or n<0);
  20.    
  21.     srand(time(NULL));
  22.    
  23.     int mayor = 0;
  24.    
  25.     for(int i=0 ; i<n ; i++){
  26.        
  27.         int numero_aleatorio = limite_inferior + rand()%(limite_superior - limite_inferior + 1);
  28.         cout<<numero_aleatorio<<" ";
  29.        
  30.         if(numero_aleatorio>mayor){
  31.             mayor = numero_aleatorio;
  32.         }
  33.     }
  34.    
  35.     cout<<"\nEl mayor numero es: "<<mayor<<endl;       
  36. }
  37.                                              
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement