gonzalob

Untitled

Jun 9th, 2020
1,176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. void mostrar(int rta);//prototipo o firma del metodo
  6. int sumar (int numero1, int numero2);
  7. char otraFuncion(char a);
  8. int POTENCIA(int base, int exponente);
  9. int FERMAT(int base, int exponente);
  10.  
  11. int main()
  12. {
  13.     int rta = 0;
  14.     //cualquier funcion que devuelva ALGO (que no sea void) tiene que ser almacenado en una variable "receptora"
  15.     // rta = sumar(1,4);
  16.     //mostrar(rta);
  17.  
  18.     //  rta = sumar(5,4);
  19.     // mostrar(rta);
  20.  
  21.     //int rtaPotencia = POTENCIA(2,3);
  22.  
  23.  
  24.     int base = 2;
  25.     int exponente = 3;
  26.     int cumple = 1;
  27.  
  28.     for (base = 2; base<=8; base++)
  29.     {
  30.         for (exponente = 3; exponente<=9; exponente=exponente+2)
  31.         {
  32.             // printf("base : %d \n",base);
  33.             // printf("exponente : %d \n",exponente);
  34.             int cumpleOno = FERMAT(base,exponente);
  35.             if (cumpleOno == 0)
  36.             {
  37.                 cumple = 0;
  38.             }
  39.         }
  40.     }
  41.  
  42.     if (cumple == 1)
  43.     {
  44.         printf("el teorema se cumple en todo el rango\n");
  45.     }
  46.     else
  47.     {
  48.         printf("el teorema NO se cumple\n");
  49.     }
  50.  
  51.     return 0;
  52. }
  53. int FERMAT(int base, int exponente)
  54. {
  55.     int valido = 0;
  56.     int rtaPotencia = POTENCIA(base,exponente);//8 ^ 3 = 512
  57.     //printf("rta %d\n",rtaPotencia);
  58.     int resta = rtaPotencia - base; //512 - 8 = 504
  59.     // printf("resta %d\n",resta);
  60.     int resto = resta % exponente;
  61.     // printf("resto %d\n",resto);
  62.  
  63.     if (resto == 0)
  64.     {
  65.         // se verifica que 504 es divisible por 3 (o sea, el teorema se cumple).
  66.         valido = 1;
  67.     }
  68.     else
  69.     {
  70.         valido = 0;
  71.     }
  72.  
  73.     return valido;
  74.  
  75.  
  76. }
  77.  
  78. int POTENCIA(int base, int exponente)
  79. {
  80.     //exponente cantidad de veces que se repite
  81.     int indice = 0;
  82.     int resultado = 1;
  83.     for (indice = 0; indice<exponente; indice++)
  84.     {
  85.         resultado = resultado * base;
  86.         // r = 1 * 2 = 2
  87.         // r = 2 * 2 = 4
  88.         // r = 4 * 2 = 8
  89.  
  90.         // r = 1 * 3 = 3
  91.         //r =  3 * 3 = 9
  92.     }
  93.     return resultado;
  94.  
  95. }
  96.  
  97.  
  98. //1 retorno void (nada) o int, float, etc
  99. //2 nombre que tiene que ser descriptivo
  100. //3 parametros entre () vacio () o enumeracion de tipo nombre , (coma)
  101. //4 cuerpo entre llaves
  102. void mostrar(int rta)
  103. {
  104.     //int p; char a;
  105.     printf("el resultado es ... %d",rta);
  106. }
  107.  
  108. int sumar (int numero1, int numero2)
  109. {
  110.     int resultado = 0;
  111.     resultado = numero1 + numero2;
  112.     //puedo llamar a otras funciones dentro de una funcion
  113.  
  114.     // mostrar(resultado);
  115.     return resultado;
  116. }
  117.  
  118. //tienen que coincidir los tipos de retorno, el de la firma con la ultima linea
  119. char otraFuncion(char a)
  120. {
  121.     char p;
  122.     return p;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment