Header Ads

Learn Together, Stay Connected.

বহুভুজের পরিসীমা-C


#include <stdio.h>
#include<math.h>
double length(double x1, double y1,double x2, double y2)
{
 return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main()
{
  int n,i;
  double sum=0;
  scanf("%d",&n);

  double point[n][2];
  for(i=0;i<n;i++)
     {
      scanf("%lf%lf",&point[i][0],&point[i][1]);
     }
  for(i=0;i<n-1;i++)
     {
      sum+=length(point[i][0],point[i][1],point[i+1][0],point[i+1][1]);
     }

      sum+=length(point[0][0],point[0][1],point[n-1][0],point[n-1][1]);
      printf("%lf\n",sum);

  return 0;

}

No comments

Theme images by Dizzo. Powered by Blogger.