Slip no : 22_2 sum of
serise using function



#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