C program- To Calculate the given series

Posted: January 19, 2012 in Lab 2

X+X^2+X^3+…. is the given series… we’ve to calculate the sum of the series for a given x….

#include<stdio.h>
#include<math.h>
int sumseries(int *, int);
int sumseries(int *x,int n)
{
	int sum=0,i;
	for(i=1;i<=n;i++)
	{
		sum=sum+pow(*x,i);
	}
	return sum;
}
int main()
{
	int x,n,sum;
	printf("Enter the value of x and n\n");
	scanf("%d%d",&x,&n);
	sum=sumseries(&x,n);
	printf("%d",sum);
}


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s