Friday, 15 April 2016

C Program To Add Two Distances (in Feet and Inches) Using Structure

Problem:- C Program To Add Two Distances ( in inch-feet ) System Using Structures In C or C program to add two distances in feet and inches using structure or C++ Program to Add Two Distances in Inch and Feet Using Structures or C Program to Add Two Distances (in inch-feet) Using Structures or C++ Program to Add Two Distances (in inch-feet) System Using Structure or Add Two Distances as feet and inches using Structure or C program to Add Two Distances (in inch-feet) or C Program to add two distances using structures.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

What Is Structure

The structure is a user-defined data type in C which allows you to combine different data types to store a particular type of record. Structure helps to construct a complex data type in a more meaningful way.

A structure is used to represent a record. Suppose you want to store a record of Student which consists of student name, address, roll number and age. You can define a structure to hold this information.

Defining a structure

struct keyword is used to define a structure. struct define a new data type which is a collection of different type of data.

Syntax :

struct structure_name
{
//Statements
};

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.

Solution:-

#include <stdio.h>

struct Distance
{
int feet;
float inch;
}d1,d2,sum;

int main()
{

//Ghanendra Yadav

printf("Enter information for 1st distance\n");
printf("Enter feet: ");
scanf("%d",&d1.feet);
printf("Enter inch: ");

scanf("%f",&d1.inch);

printf("\nEnter information for 2nd distance\n");
printf("Enter feet: ");

scanf("%d",&d2.feet);

printf("Enter inch: ");

scanf("%f",&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\'-%.1f\"",sum.feet,sum.inch);

return 0;

}

Output:-

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment