FY_BCA_C_SLIP 22_2



Slip no : 22_2 sum of serise using function
sum = 1+1/x+1/x2+1/x3+1/x4+.....


#include<stdio.h>
//#include<dos.h>
//#include<math.h>

int s(int x,int i)
{
int power=1; do

{
power=power*x; i--;
}while(i);

return power;
}

main()
{
int i,x,n; float sum,p;

printf("\n Enter the base value:"); scanf("%d",&x);
printf("\n Enter the power value:"); scanf("%d",&n);
i=1;
sum=1;

while(i<=n)
{
p=s(x,i);
sum=sum+(1/p);
i=i+1;
}

printf("\n Sum is series = %f",sum); getch();
}

No comments:

Post a Comment