Skip to content

Commit fe8830f

Browse files
authored
Calculate the Harmonic series
1 parent 4befc1a commit fe8830f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Harmonic_series.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*DAVIDE GIANNUBILO - Esercizi Linguaggio C
2+
Scrivere un programma che calcoli la serie armonica di un numero N inserito in ingresso
3+
Write a program that calculates the Harmonic series of a number N given in input
4+
*/
5+
6+
#include<stdio.h>
7+
8+
int main()
9+
{
10+
int num;
11+
printf("Inserisci il numero n: ");
12+
scanf("%d", &num);
13+
14+
if(num<=0)
15+
{
16+
printf("Errore! Numero <= 0\n");
17+
return 0;
18+
}
19+
else
20+
{
21+
float somma;
22+
for(float i=1; i<=num; i++)
23+
{
24+
somma=somma+1/i;
25+
}
26+
printf("La serie armonica vale: %f\n", somma);
27+
}
28+
29+
return 0;
30+
}

0 commit comments

Comments
 (0)