Created
September 7, 2020 07:22
-
-
Save shemul/3181dec8288d623a198763b2f44546ee to your computer and use it in GitHub Desktop.
simple c program with external header file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CArea | |
{ | |
int x; | |
int y; | |
} CArea; | |
double area(struct CArea area_samp) | |
{ | |
return 0.5 * area_samp.x * area_samp.y; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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