Friday, 15 April 2016

C Program To Add Two Distances ( in inch-feet ) Using Structures

Problem :- C Program To Add Two Distances ( in inch-feet ) System Using Structures In C .

What Is Structure 

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 more meaningful way. It is somewhat similar to an Array. The only difference is that array is used to store collection of similar datatypes while structure can store collection of any type of data.

Structure is used to represent a record. Suppose you want to store 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


Solution :-

#include <stdio.h>

struct Distance{
    int feet;
    float inch;
int main()
//Ghanendra Yadav
    printf("Enter information for 1st distance\n");
    printf("Enter feet: ");
    printf("Enter inch: ");
    printf("\nEnter information for 2nd distance\n");
    printf("Enter feet: ");
    printf("Enter inch: ");

    if (sum.inch>12.0)

    printf("\nSum of distances=%d\'-%.1f\"",sum.feet,sum.inch);
    return 0;


c program to add two distances in inch feet system using structures

No comments:
Write comments

Recommended Posts × +