/*Print harmonic series*/
#include<stdio.h> //header file
void main()
{
int Val,i; //initialize variable
float sum,var;
sum=0.0;
var=0.0;
printf("Enter number of terms for harmonic series :");
scanf("%d",&Val); //get the value in run time
for(i=1;i<=Val;i++) //loop for printing harmonic series and logic
{
var=1./i;
sum+=var;
}
printf(" sum of harmonic series for %d,%f",Val,sum);
} //end of main
Common Programmin Error :-
Logic is more important for that you can take reference from school books.Common error happned in for loop.
Good Programming Practice:-
Alaways use areithematice operator in different manner.
No comments:
Post a Comment