Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Exercicio 1
- //
- //i x j
- //0 10 0
- //3 10 0
- //6 10 2
- //... ... ...
- //15 10 8
- //15+1 10 8
- //
- //Resposta : 16
- //Exercicio 2 a)
- typedef float Matriz
- //Exercicio 2 b)
- bool MatrizSimetrica(Matriz *M, int nl, int nc)
- {
- int i, j;
- if(nl == nc)
- {
- for(i=0; i<nl; i++)
- for(j = i+1; j<nc; j++)
- if(*(M+i*nc+j) == *(M+j*nc+i))
- return true;
- }
- return false;
- }
- //Exercicio 3 a)
- typedef struct
- {
- float altura;
- float massa;
- int genero; //eu usei bool primeiro, tipo 1 (true) = macho e 0 (false) = fémea xD mas esqueçam este comentário
- struct
- {
- int ano;
- int mes;
- int dia;
- } //pode-se fazer sem este struct, mas assim realça-se a data xD
- }Individuo;
- //Exercicio 3 b)
- int Saudaveis(Individuo *vect_ind, int n_ind)
- {
- float IMC=0;
- int i, a=0;
- for(i=0; i<n_ind; i++)
- {
- IMC = (vect_ind+i)->massa/(vect_ind+i)->altura * (vect_ind+i)->altura;
- if(IMC >= 18.5 && IMC <= 24.9)
- a++;
- }
- return a;
- }
- //Exercicio 3 c)
- float MediaSecPassado(Individuo *vect_ind, int n_ind)
- {
- int i, a=0;
- float massasoma;
- for(i=0; i<n_ind; i++);
- if((vect_ind+i)->ano < 2000)
- {
- massasoma = (vect_ind+i)->massa;
- a++;
- }
- return massasoma/a;
- }
- //Exercicio 4 a)
- float SomaIt(int N)
- {
- int i=1, a=1;
- long fact;
- float soma=0;
- for(i; i<=N; i++)
- {
- fact=a*i;
- a=fact;
- soma += (1.0f/fact)+fact;
- }
- return soma;
- }
- //Exercicio 4 b)
- float SomaRec(int N, int i)
- {
- long a;
- long fact = 1;
- for(a=i; a>0; a--)
- fact=fact*a;
- if(i < N)
- return (1.0f/fact)+fact+SomaRec(N, ++i);
- else return (1.0f/fact)+fact;
- }
- //Exercicio 5
- void EscreveDivisores(int N)
- {
- int i;
- printf("Divisores:\n");
- for(i=1.0f; i<=N; i++)
- if(N%i == 0)
- printf("%d\t", i);
- printf("\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