Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.00 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define MAX_FATTORI 9999
  4. #define MAX_RISULTATO 99999999
  5.  
  6.  
  7. int lettura_dati(int x)
  8. {
  9.  
  10.     int numero4, numero8;
  11.  
  12.     if (x==0)
  13.     {
  14.         do
  15.         {
  16.             printf("\nInserire un numero di 4 cifre \n");
  17.             scanf("%d", &numero4);
  18.             if(numero4>MAX_FATTORI)
  19.             {
  20.                 printf("\nErrore, inserire un numero con almeno 4 cifre\n");
  21.             }  
  22.  
  23.         } while(numero4>MAX_FATTORI);
  24.            
  25.         return numero4;
  26.    
  27.     }
  28.     else if(x==1)
  29.     {
  30.         do
  31.         {
  32.             printf("\nInserisci il risultato di 8 cifre \n");
  33.             scanf("%d", &numero8);
  34.             if(numero8>MAX_RISULTATO)
  35.             {
  36.                 printf("\nErrore, il risultato deve avere almeno  8 cifre\n");  
  37.             }
  38.  
  39.         }while (numero8>MAX_RISULTATO);
  40.  
  41.         return numero8;
  42.     }
  43.     return 0;
  44. }
  45.  
  46.  
  47. int scomposizione_numeri(int radice_numerica)
  48. {
  49.     int modulo; //dichiarazione di una variabile
  50.     int somma=0;
  51.     int rn;
  52.  
  53.     while(radice_numerica!=0)
  54.     {
  55.         modulo = radice_numerica % 10;
  56.         radice_numerica/=10;
  57.         somma += modulo;
  58.         printf("\nRadice numerica %d\n", radice_numerica);
  59.         printf("\nSomma %d\n", somma);
  60.     }
  61.  
  62.     rn = somma;
  63.  
  64.     if(rn>9)
  65.     {
  66.  
  67.     printf("\nSeconda radice\n");
  68.     return scomposizione_numeri(rn);
  69.    
  70.     }
  71.  
  72.     printf("\nModulo di Radice numerica%d\n", rn);
  73.     return rn;
  74. }
  75.  
  76. int main()
  77. {
  78.     int numero1=lettura_dati(0);
  79.     int numero2=lettura_dati(0);
  80.     int risultato=lettura_dati(1);
  81.  
  82.     int valore1=scomposizione_numeri(numero1);
  83.     int valore2=scomposizione_numeri(numero2);
  84.     int rnfinale=scomposizione_numeri(risultato);
  85.     int risultato1 = valore1 * valore2;
  86.  
  87.     if (risultato1 == rn)
  88.     {
  89.         printf("\nIl valore e` sicuro all`11 per cento\n");
  90.         return 0;
  91.     }
  92.     else
  93.     {
  94.         printf("\nIl valore non e` corretto\n");
  95.         return 1;
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement