URI Online Judge | 1155
Sequência S
Adaptado por Neilor Tonin, URI
Brasil
Timelimit: 1 
Escreva um algoritmo para calcular e escrever o valor de S, sendo S dado pela fórmula:
S = 1 + 1/2 + 1/3 + … + 1/100
S = 1 + 1/2 + 1/3 + … + 1/100
Entrada
Não há nenhuma entrada neste problema.
Saída
A saída contém um valor correspondente ao valor de S.
O valor deve ser impresso com dois dígitos após o ponto decimal.
O valor deve ser impresso com dois dígitos após o ponto decimal.
URI Online Judge | 1155
S Sequence
Adapted by Neilor Tonin, URI
Brazil
Timelimit: 1
Write an algorithm to calculate and write the value of S, S being given by:
S = 1 + 1/2 + 1/3 + … + 1/100
S = 1 + 1/2 + 1/3 + … + 1/100
Input
There is no input in this problem.
Output
The output contains a value corresponding to the value of S.
The value should be printed with two digits after the decimal point.
The value should be printed with two digits after the decimal point.
#include <stdio.h>
int main()
{
double a,b=1,c, S=0;
for(a=1; a<=100; a++)
{
c=1/a;
S+=c;
}
printf("%.2lf\n",S);
return 0;
}
Nenhum comentário:
Postar um comentário