Create a structure and access it using pointers to structures in C

#include <stdio.h>
 
struct point{
   float abscissa;
   float ordinate;
};
struct point mid(struct point,struct point);
 
int main()
{
   struct point p1,p2,pm;
 
   printf("Enter coordinates of two points:n");
   printf("tFor the first point (x1,y1) : ");
   scanf("%f,%f",&p1.abscissa,&p1.ordinate);
   fflush(stdin);
   printf("tFor the second point (x2,y2) : ");
   scanf("%f,%f",&p2.abscissa,&p2.ordinate);
   pm=mid(p1,p2);
   printf("The middle point is :
                            (%f,%f).n",pm.abscissa,pm.ordinate);
   return 0;
}
 
struct point mid(struct point a,struct point b)
{
   a.abscissa=(a.abscissa+b.abscissa)/2;
   a.ordinate=(a.ordinate+b.ordinate)/2;
   return a;
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.