Subscribe for more such posts..

Dear Reader...
I hope u are like my posts. If so then please don't forget to like , share and follow my blog for more such posts ,also feel free to write suggestions in the comment box given over here.

Thank you...

Search This Blog

C program to compute the Sum of the Series 1 + x + x2 + x3 + …………. +xn.


 

#include <stdio.h>
#include <math.h>
int main()
{
	int x , n , sum = 1 , value , i;
	printf("Enter x and n : ");
	scanf("%d %d" , &x , &n);

	
	if(x < 0 ||n < 0)
	{
		printf("Illegal values\n");
	}
		else
		{
			printf("Sum of series : ");
	
		for(i = 1 ; i <= n ; i++)
		{
			value = pow(x , i);
			sum = sum + value ;
		}
	
		
		printf("%d\n" , sum);
		
		}
	

	
	return 0;
}


No comments:

Post a Comment