Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- void mostrar(int rta);//prototipo o firma del metodo
- int sumar (int numero1, int numero2);
- char otraFuncion(char a);
- int POTENCIA(int base, int exponente);
- int FERMAT(int base, int exponente);
- int main()
- {
- int rta = 0;
- //cualquier funcion que devuelva ALGO (que no sea void) tiene que ser almacenado en una variable "receptora"
- // rta = sumar(1,4);
- //mostrar(rta);
- // rta = sumar(5,4);
- // mostrar(rta);
- //int rtaPotencia = POTENCIA(2,3);
- int base = 2;
- int exponente = 3;
- int cumple = 1;
- for (base = 2; base<=8; base++)
- {
- for (exponente = 3; exponente<=9; exponente=exponente+2)
- {
- // printf("base : %d \n",base);
- // printf("exponente : %d \n",exponente);
- int cumpleOno = FERMAT(base,exponente);
- if (cumpleOno == 0)
- {
- cumple = 0;
- }
- }
- }
- if (cumple == 1)
- {
- printf("el teorema se cumple en todo el rango\n");
- }
- else
- {
- printf("el teorema NO se cumple\n");
- }
- return 0;
- }
- int FERMAT(int base, int exponente)
- {
- int valido = 0;
- int rtaPotencia = POTENCIA(base,exponente);//8 ^ 3 = 512
- //printf("rta %d\n",rtaPotencia);
- int resta = rtaPotencia - base; //512 - 8 = 504
- // printf("resta %d\n",resta);
- int resto = resta % exponente;
- // printf("resto %d\n",resto);
- if (resto == 0)
- {
- // se verifica que 504 es divisible por 3 (o sea, el teorema se cumple).
- valido = 1;
- }
- else
- {
- valido = 0;
- }
- return valido;
- }
- int POTENCIA(int base, int exponente)
- {
- //exponente cantidad de veces que se repite
- int indice = 0;
- int resultado = 1;
- for (indice = 0; indice<exponente; indice++)
- {
- resultado = resultado * base;
- // r = 1 * 2 = 2
- // r = 2 * 2 = 4
- // r = 4 * 2 = 8
- // r = 1 * 3 = 3
- //r = 3 * 3 = 9
- }
- return resultado;
- }
- //1 retorno void (nada) o int, float, etc
- //2 nombre que tiene que ser descriptivo
- //3 parametros entre () vacio () o enumeracion de tipo nombre , (coma)
- //4 cuerpo entre llaves
- void mostrar(int rta)
- {
- //int p; char a;
- printf("el resultado es ... %d",rta);
- }
- int sumar (int numero1, int numero2)
- {
- int resultado = 0;
- resultado = numero1 + numero2;
- //puedo llamar a otras funciones dentro de una funcion
- // mostrar(resultado);
- return resultado;
- }
- //tienen que coincidir los tipos de retorno, el de la firma con la ultima linea
- char otraFuncion(char a)
- {
- char p;
- return p;
- }
Advertisement
Add Comment
Please, Sign In to add comment