Thursday, 18 January 2018

11-D 22. Write a algorithm and program to find the sum of series s=1+x+x2+x3………….xn? Using function( non void with argument)

Algorithm

Input:
1. n
2. x

Output:
1. sum

Method:     //main program
1. start
2. read n and x
3. print n and x
4. sums=sum_seri(n, x);  //function calling
5. print"sum of series",sums
6. stop


//write the function definition before the main program

float sum_ser(int n, float x)   function definition
begin
      sum=1;
    for(i=1; i< n; i++)
    begin
         sum = sum + pow(x,i);
    end
  return sum;
end

 
 

No comments:

Post a Comment