This repository has been archived on 2023-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
VSMechatronics/LC19/StructureFunction/StructureFunc.c

36 lines
617 B
C

#include <stdio.h>
#include <math.h>
struct Point /* Define a struture called Point */
{
int x; /* The X data */
int y; /* The Y data */
};
struct Line
{
struct Point p1;
struct Point p2;
float length;
};
void LineLength( struct Line* line);
int main()
{
struct Line line;
line.p1.x = 0;
line.p1.y = 0;
line.p2.x = 3;
line.p2.y = 4;
LineLength( &line );
printf( "Line length = %.3f\n", line.length);
}
void LineLength( struct Line* line)
{
float dx = line->p2.x - line->p1.x;
float dy = line->p2.y - line->p1.y;
line->length = sqrt( dx*dx + dy*dy );
}