TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Computação II

Por:   •  18/5/2016  •  Trabalho acadêmico  •  799 Palavras (4 Páginas)  •  126 Visualizações

Página 1 de 4

* RESOLUÇÃO DE QUESTÕES

- Sendo H definido pela expressão abaixo, faça um programa com uso de um laço

for para receber o valor de N, inteiro, calcular e exibir o valor de H.

H = 1 + 1/2 + 1/3 + ... + 1/N.

* SOLUÇÃO COM LAÇO do...while

#include <stdio.h>

#include <stdlib.h>

int main()

{

float vc, n, h = 0;

printf("CALCULO DE H, DADO PELA EXPRESSAO H = 1/1 + 1/2 + 1/3 + ... + 1/N\n\n\n");

printf("ENTRE COM O VALOR DE N: ");

scanf("%f", &n);

vc = 1;

do

{

h = h + 1/vc;

++vc;

}

while(vc <= n);

printf("\n\nH = %.2f\n\n\n", h);

system("pause");

return 0;

}

* SOLUÇÃO COM LAÇO while

#include <stdio.h>

#include <stdlib.h>

int main()

{

float vc, n, h = 0;

printf("CALCULO DE H, DADO PELA EXPRESSAO H = 1/1 + 1/2 + 1/3 + ... + 1/N\n\n\n");

printf("ENTRE COM O VALOR DE N: ");

scanf("%f", &n);

vc = 1;

while(vc <= n)

{

h = h + 1/vc;

++vc;

}

printf("\n\nH = %.2f\n\n\n", h);

system("pause");

return 0;

}

* SOLUÇÃO COM LAÇO for

#include <stdio.h>

#include <stdlib.h>

int main()

{

float vc, n, h = 0;

printf("CALCULO DE H, DADO PELA EXPRESSAO H = 1/1 + 1/2 + 1/3 + ... + 1/N\n\n\n");

printf("ENTRE COM O VALOR DE N: ");

scanf("%f", &n);

for(vc = 1; vc <= n; ++vc)

{

h = h + 1/vc;

}

printf("\n\nH = %.2f\n\n\n", h);

system("pause");

return 0;

}

- Faça um algoritmo que leia um número N, inteiro positivo,

calcule e mostre os N primeiros termos da seqüência de

Fibonacci (0, 1, 1, 2, 3, 5, 8, 13, ...).

* SOLUÇÃO COM LAÇO for

#include <stdio.h>

#include <stdlib.h>

int main()

{

int n, vc, ant1 = 0, ant2 = 1, prox;

printf("EXIBICAO DOS n PRIMEIROS ELEMENTOS DA SERIE DE FIBONACCI\n\n\n");

printf("ENTRE COM O VALOR DE n: ");

scanf("%d", &n);

if(n == 1)

{

printf("\n\n%d", ant1);

}

if(n == 2)

{

printf("\n\n%d %d", ant1, ant2);

}

if(n > 2)

{

printf("\n\n%d %d ", ant1, ant2);

for(vc = 3; vc <= n; vc++)

{

prox = ant1 + ant2;

printf("%d ", prox);

ant1 = ant2;

ant2 = prox;

...

Baixar como (para membros premium)  txt (3.7 Kb)   pdf (164 Kb)   docx (12.9 Kb)  
Continuar por mais 3 páginas »
Disponível apenas no TrabalhosGratuitos.com