WAP TO FIND SUM OF INVERSE OF N NATURAL NUMBERS

/*WAP TO FIND SUM OF INVERSE OF N NATURAL NUMBERS*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
float i,inv,sum=0;
clrscr();
printf(“Enter the range: “);
scanf(“%d”,&n);
printf(“Inverse of first %d natural numbers is: \n”,n);
for(i=1;i<=n;i++)
{
inv=1/i;
sum=sum+inv;
printf(“%f\n”,inv);
}
printf(“Sum of inverse of %d natural numbers is: %f”,n,sum);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *