Q : Define a structure Distance having two data members: cm and mm in integer. The program enters three variables and find which distance is the largest among them.
Answer
#include<stdio.h>
#include<conio.h>
/*============================
Girfa Student Help
Find greatest cm:mm using structure
==============================*/
struct len
{
float cm;
float mm;
};
void main()
{
int a,b,c;
struct len v1,v2,v3;
clrscr();
printf("Enter
first cm:mm>> ");
scanf("%f%f",&v1.cm,&v1.mm);
printf("Enter
second cm:mm>> ");
scanf("%f%f",&v2.cm,&v2.mm);
printf("Enter
third cm:mm>> ");
scanf("%f%f",&v3.cm,&v3.mm);
a=v1.cm+(v1.mm/10);
b=v2.cm+(v2.mm/10);
c=v3.cm+(v3.mm/10);
if(a>b)
{
if(b>c)
puts("First Variable is a is greater");
else
puts("Third Variable is a is greater");
}
else
{
if(b>c)
puts("Second Variable is a is greater");
else
puts("Third Variable is a is greater");
}
getch();
}
No comments:
Post a Comment