Define a struct type with the name Length that represents a
Solution
#include <stdio.h>
struct Length //structure Length
{
int yards;
int feet;
int inches;
};
struct Length add(struct Length,struct Length); //prototypes for functions
void show(struct Length);
int main(void)
{
struct Length l1,l2,l3;
printf(\"\ Enter Length in Yards ,feet and inches of l1\");
scanf(\"%d %d %d\",&l1.yards,&l1.feet,&l1.inches);
printf(\"\ Enter Length in Yards ,feet and inches of l2\");
scanf(\"%d %d %d\",&l2.yards,&l2.feet,&l2.inches);
l3 = add(l1,l2); //adding two structure variables and assign the sum to another structure variable
show(l3);
return 0;
}
struct Length add(struct Length l1,struct Length l2) //add function
{
struct Length temp;
temp.yards=l1.yards+l2.yards;
temp.feet = l1.feet+l2.feet;
temp.inches =l1.inches+l2.inches;
return temp;
}
void show(struct Length l) //show function
{
printf(\"\ %d yards\",l.yards);
printf(\"\ %d feet\",l.feet);
printf(\"\ %d inches\",l.inches);
}
output:
