Write a program to create the series 1+1/2+1/3+….

#include<conio.h>
#include<stdio.h>
int main()
{
float ans=0.0;
int terms,i=1;
printf("Enter no of terms");
scanf("%d",&terms);
while(i<=terms)
{
ans = ans+(float)1/i;
i++;
}
CPU-2110003 CPU Program
V.V.P Engineering College Developed By: Tejas Rupani
printf("\nans is: %f",ans);
}

No comments:

Post a Comment