Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Exercicio 1
- //i x
- //0 1
- //3 2
- //6 3
- //9 4
- //
- //Resposta: 9 porque o i++ mostra o 9 e só depois é que adiciona
- //Exercicio 2
- bool perfeito(int n)
- {
- int i, soma=0;
- for(i=n-1; i>0; i--)
- {
- if(n%i == 0)
- soma += i;
- }
- if(soma == n)
- return true;
- else return false;
- }
- void NumPerfeito(int N)
- {
- int i;
- for(i=1; i<=N; i++)
- {
- if(perfeito(i))
- printf("%d\t", i);
- }
- }
- //Exercicio 3 a)
- typedef struct
- {
- char NomeCidade[MAX_CIDADE];
- int Mes[N_MESES];
- int Entradas[N_MESES];
- }Acessos;
- //Exercicio 3 b)
- void MinimoMes(Acessos *vect)
- {
- int aux[N_MESES], i, j;
- for(i=0; i<N_MESES; i++)
- {
- aux[i] = 0;
- for(j=0; j<N_CIDADES; j++)
- if((vect+j)->Entradas[i] > aux[i])
- aux[i] = (vect+j)->Entradas[i];
- printf("%d\t", aux[i]);
- }
- }
- //Exercicio 3 c)
- void MaisAcessos(Acessos *vect)
- {
- int aux=0, i, j, ai, aj;
- for(i=0; i<N_MESES; i++)
- for(j=0; j<N_CIDADES; j++)
- if((vect+j)->Entradas[i] > aux)
- {
- ai = i;
- aj = j;
- aux = (vect+j)->Entradas[i];
- }
- printf("O mes com mais acessos foi %d na cidade %d", ai, aj);
- }
- //Exercicio 3 d)
- //Nao faço a minima como o fazer mas suponho que seja isto : :/
- #define MAX_ANOS 10
- Acessos Ace[MAX_ANOS];
- //Exercicio 4 a)
- float SomatIt(int N)
- {
- int i, j;
- long pot=9, fact=1;
- float frac, soma=0;
- for(i=1; i<=N; i++)
- {
- pot *= 3;
- for(j=1; j<i; j++)
- fact *= j;
- frac = pot/fact;
- soma += frac+(2*i);
- }
- return soma;
- }
- //Exercicio 4 b) Acho que é assim :/
- float SomatRec(int N, long pot, long fact, float soma, int i)
- {
- int frac;
- pot *= 3;
- fact *= i-1;
- frac = pot/fact;
- soma += frac + (2*i);
- if(i<N)
- return soma+SomatRec(N, pot, fact, soma, ++i);
- return soma;
- }
- //Exercicio 5
- bool perfeito(int n)
- {
- int i, soma=0;
- for(i=n-1; i>0; i--)
- {
- if(n%i == 0)
- soma += i;
- }
- if(soma == n)
- return true;
- else return false;
- }
- void PrimPerf(int n)
- {
- printf("Primeiros %d numeros perfeitos\n", n);
- int i=0, a=1;
- do
- {
- if(perfeito(a))
- {
- printf("%d\t", a++);
- i++;
- }
- }while(i != n);
- }
- //Exercicio 6
- #include <stdio.h>
- #include <malloc.h>
- int Fib(int N)
- {
- if(N == 0 || N == 1)
- return N;
- else return Fib(N-1)+Fib(N-2);
- }
- void LerVector(int *Vec, int n)
- {
- int i;
- for(i = 0; i<n; i++)
- {
- printf("Qual o valor da posicao [%d]:", i);
- scanf("%d", Vec++);
- }
- }
- int *AlocarVector(int n)
- {
- int*A;
- A = (int*)malloc(n*sizeof(int));
- if(A == NULL)
- {
- printf("\nMemoria Insuficiente.");
- return 0;
- }
- return A;
- }
- void main()
- {
- int *VecA, n, i;
- printf("Diga o numero de lelementos:");
- scanf("%d", &n);
- VecA = AlocarVector(n);
- LerVector(VecA, n);
- for(i=0;i<n;i++)
- printf("%d\t", Fib(*(VecA++)));
- }
Advertisement
Add Comment
Please, Sign In to add comment