Code
WAP in C using structure to add lengths in feet and inch.
A simple program that I solved in C.
Rate
// 12 inch = 1 feet
#include
int main(){
double tempInch;
typedef struct dis{
double feet, inch;
}distance;
distance x1, x2, sum;
int increment;
printf("Enter the values in (feet, inch) for x1 and x2:\n");
scanf("%lf %lf %lf %lf", &x1.feet, &x1.inch, &x2.feet, &x2.inch);
sum.feet = x1.feet+x2.feet;
sum.inch = x1.inch+x2.inch;
if (sum.inch>=12)
{
tempInch = sum.inch;
increment = (int)tempInch/12;
// printf("increment = %d\n", increment);
sum.inch -= increment*12;
sum.feet += increment;
}
printf("%.2lf'%.2lf\" + %.2lf'%.2lf\" = %.2lf'%.2lf\"", x1.feet, x1.inch, x2.feet, x2.inch, sum.feet, sum.inch);
return 0;
}
Add comment:
Total 0 comments