½(x-1)/x + ½(x-1/x) 2 + ½ (x-1/x) 3+…. solve this ( loop series )



 



#include<stdio.h>
#include<conio.h>
#include<math.h>
int main(int argc, char const *argv[])
{
  int x,n,i;
  float m,c,y,sum=0;

  printf("enter the value of x and n :");
  scanf("%d %d",&x,&n);

   c=(x-1.00)/x;   
    
  for ( i = 1; i <= n; i++)
  {
    y=pow(c,i);
    printf(" %f",y);
    sum=sum+y;
  }

    m=sum/2;
  printf("\nsum of series = %f",m);
  return 0;

}

output :

enter the value of x and n :4 6 0.750000 0.562500 0.421875 0.316406 0.237305 0.177979 sum of series = 1.233032

Comments

Popular Post

Create a base class called shape .Use this class to store two double type values that could be used to compute the area of figures, Derive two specific classes called triangle and rectangle from the base shape .Add to the base class, a member function get_data() to initialise base class data members and another member function display_area() to compute and display the area of figures. Make display_area () as a virtual function and redefine this function in the derived class to suit their requirements. Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively and display the area. Area of rectangle = x*y Area of triangle = ½*x*y