Advertisement
nasho97

Mod1Cuest3Preg4

Aug 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. //Ignacio Alejandro Ruiz Garrido
  2. //14 de Agosto
  3. //Números Interesantes
  4. //Buscar dentro de un rango de números, el mayor número interesante
  5.  
  6. #include<stdio.h>
  7.  
  8. int main ()
  9. {
  10.     unsigned short limInf;
  11.     unsigned short limSup;
  12.     unsigned short Suma;
  13.     unsigned short CantDiv;
  14.     unsigned short Num;
  15.     unsigned short aux;
  16.     unsigned short Interesante=0;
  17.     unsigned short MaxDiv=0;
  18.     unsigned short MaxSuma=0;
  19.     unsigned short flag=0;
  20.    
  21.     scanf("%hu %hiu",&limInf,&limSup);
  22.     printf ("%hu limsup %hu",&limInf,&limSup);
  23.    
  24.     for (Num=limInf;Num<=limSup;Num++)
  25.     {
  26.         Suma=0;
  27.         CantDiv=0;
  28.        
  29.         for (aux=1;aux<=(Num/2);aux++)
  30.         {
  31.             if ((Num%aux)==0)
  32.             {
  33.                 CantDiv++;
  34.                 Suma=Suma+aux;
  35.             }
  36.         }
  37.         if (Suma>Num)
  38.             {
  39.                 flag=1;
  40.                 if (CantDiv>MaxDiv)
  41.                 {
  42.                     MaxSuma=Suma;
  43.                     MaxDiv=CantDiv;
  44.                     Interesante=Num;
  45.                 }
  46.             }
  47.     }
  48.     if (flag)
  49.     {
  50.         printf("Entre %hu y %hu, el numero %hu tiene %hu divisores y la suma de sus divisores es %hu",&limInf,&limSup,&Interesante,&MaxDiv,&MaxSuma);
  51.     }
  52.     else
  53.     {
  54.         printf ("No se encontro numero que cumpliera las condiciones!");
  55.     }
  56.    
  57.     return 0;
  58.    
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement