Skip to content

Instantly share code, notes, and snippets.

@shemul
Created September 7, 2020 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shemul/3181dec8288d623a198763b2f44546ee to your computer and use it in GitHub Desktop.
Save shemul/3181dec8288d623a198763b2f44546ee to your computer and use it in GitHub Desktop.
simple c program with external header file
struct CArea
{
int x;
int y;
} CArea;
double area(struct CArea area_samp)
{
return 0.5 * area_samp.x * area_samp.y;
}
/*
Declare a structure ( i.e. a type) called CArea & a set (i.e. , a variable) of this structure called signature samp. This structure contains two data members of type int (member x & member y). Calculate the area of the triangle ( area=0.5*x*y ) . Display all the values considered for calculating an area & the area itself. lmplement the full code with C language & other necessary functions to run it.
Bonus : if you can implement it using HEADER file concept.
*/
#include <stdio.h>
#include "CArea.h"
int main()
{
struct CArea geom;
geom.x = 12;
geom.y = 14;
double result;
result = area(geom);
printf("X : %d\n", geom.x);
printf("Y : %d\n", geom.y);
printf("Area : %lf\n", result);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment