0
4.6kviews
Write a C program to add two distances(feet-inch system) enter by user , using structures.

Mumbai University> FE > Sem 2> STRUCTURED PROGRAMMING APPROACH

Marks: 10 M

Year: Dec 2016

1 Answer
0
34views
#include<stdio.h>
#include<conio.h>
struct distance
{   
int feet;
float inch;
}
main()
{
struct distance d1,d2,sum;
printf(“Enter First Distance: ”);
printf(“Enter feet: ”);
scanf(“%d”,&d1.feet);
printf(“Enter inch: ”);
scanf(“%d”,&d1.inch);

printf(“Enter Second Distance: ”);
printf(“Enter feet: ”);
scanf(“%d”,&d2.feet);
printf(“Enter inch: ”);
scanf(“%d”,&d2.inch);

sum.feet=d1.feet+d2.feet;
sum.inch=d1.inch+d2.inch;

if(sum.inch>12.0)
{
sum.inch=sum.inch-12.0;
sum.feet++;
}
printf(“\nSum of distances = %d feet and %.2f”,sum.feet,sum.inch);
getch();
}

Output:
Enter First Distance:
Enter feet:4
Enter inch:8
Enter Second Distance:
Enter feet:5
Enter inch:6
Sum of distances= 10 feet and 2.00 inch
Please log in to add an answer.

Continue reading...

The best way to discover useful content is by searching it.

Search