Create a process that will calculate the series 1 x x2 x3
Create a process that will calculate the series
1 + x + x2 + x3 + x4 ………. + xn
where x is a floating point number and n is a positive number. You process should be designed so exponentiation functions are not needed.
Your main function should prompt the user to enter a whole number for n and a floating point number for x. Assume the users input is valid (you do not have to check it unless you want to do so for practice). Then the main function should call your function to calculate the series, store the value returned into a variable, and output the variable that contains the sum.
**Remember do not use break or continue in a loop and do not use the same variable name in multiple functions). Also remember for this course function definitions should appear after main and you should use function declarations (prototypes). In additional to the overall program comments, each function other than main should have comments immediately preceding the function that describe the purpose of the function, input to the function (by what is passed to the function and any input from the user while the function is running), output from the function (what is returned to the function call and any results that are output to the screen), and processing that takes place in the function
Your value-return function should accept two parameters: a floating point parameter and a whole number parameter. Inside the function declare a variable to store the sum and use a loop to calculate the sum ( you may declare and use other variables as well). After the sum has been completed, return the sum to the function call.
Solution
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n;
float x,sum=0;
clrscr(); //to clear the screen
printf(“1+x+x^2+……+x^n”);
printf(“nnEnter the value of x and n:”);
scanf(“%f%d”,&x,&n);
for(i=1;i<=n;++i)
sum+=pow(x,i);
sum++;
printf(“nSum=%f”,sum);
getch(); //to stop the screen
}
out put :
1+x+x^2+……+x^n
Enter the value of x and n:3
5
sum=364

