সোমবার, ২৭ এপ্রিল, ২০২০

Write a C program to determine the sum of the following harmonic series for a given value of N. 1 + ½ + 1/3 + ……….. + 1/n.


Write a C program to determine the sum of the following harmonic series for a given value of N.
1 + ½ + 1/3 + ………..  + 1/n.




Algorithm:
Step 1: Start
Step 2: Input the value of N
Step 3: Initialized i=1
Step 4: While i<=n repeat step 5
Step 5: sum=sum+(1.0/i), i++
Step 6: Print the sum is
Step 7: End
 


C Program:


#include<stdio.h>
int main()
{
    int n, i;
    float sum=0.0;
    printf ( “ Input an Integer Number : “);
    scanf("%d", &n);
    for (i=1; i<=n; i++)
    {
        sum=sum+(1.0/i);
    }
    {
        printf(" %.3f",sum);
    }
    return 0;
}

লেবেলসমূহ:

0টি মন্তব্য:

একটি মন্তব্য পোস্ট করুন

এতে সদস্যতা মন্তব্যগুলি পোস্ট করুন [Atom]

<< হোম