0% found this document useful (0 votes)
17 views

Point

The document contains 3 C programs that use structures. The first program defines a point structure and calculates the distance between two points. The second program defines a time structure and converts hours, minutes, seconds to total seconds. The third program defines an employee structure containing name, salary, and date of birth structures and prints details of employees born in 1995.

Uploaded by

Abdullah Abid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Point

The document contains 3 C programs that use structures. The first program defines a point structure and calculates the distance between two points. The second program defines a time structure and converts hours, minutes, seconds to total seconds. The third program defines an employee structure containing name, salary, and date of birth structures and prints details of employees born in 1995.

Uploaded by

Abdullah Abid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<math.h>
struct point {
float x;
float y;
};
float distance(struct point p1, struct point p2);
void main()
{
struct point a, b;
float result;
printf("Enter value of X1=");
scanf_s("%f", &a.x);
printf("Enter value of Y1=");
scanf_s("%f", &a.y);
printf("Enter value of X2=");
scanf_s("%f", &b.x);
printf("Enter value of Y2=");
scanf_s("%f", &b.y);
result = distance(a, b);
printf("distance=%f\n", result);
}
float distance(struct point p1, struct point p2)
{
float ans;
ans = sqrt(pow((p2.x-p1.x),2)+pow((p2.y-p1.y),2));
return ans;
}

#include<stdio.h>
#include<math.h>
struct time {
int hours;
int min;
int sec;
};
int seconds(struct time *t);
void main()
{
struct time t;
int result;
printf("Enter Hours=");
scanf_s("%d", &t.hours);
printf("Enter Minutes=");
scanf_s("%d", &t.min);
printf("Enter Seconds=");
scanf_s("%d", &t.sec);
result = seconds(&t);
printf("Seconds=%d\n", result);
}
int seconds(struct time *t)
{
int ans;
ans = (t->hours * 3600) + (t->min*60) + (t->sec);
return ans;
}

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
struct date {
int date;
int month;
int year;
};
struct employee{
char name[10];
float salary;
struct date dob;
};
void main()
{
struct employee x[5];
int i;
for (i = 0; i < 5; i++)
{
printf("Enter Name=");
scanf("%s", x[i].name);
printf("Enter Salary=");
scanf_s("%f", &x[i].salary);
printf("Enter Date=");
scanf_s("%d", &x[i].dob.date);
printf("Enter Month=");
scanf_s("%d", &x[i].dob.month);
printf("Enter Year=");
scanf_s("%d", &x[i].dob.year);
}
for (i = 0; i < 5; i++)
{
if (x[i].dob.year == 1995)
{
printf("Name is %s\n", x[i].name);
printf("Salary is %f\n", x[i].salary);
printf("Date is %d\n", x[i].dob.date);
printf("Month is %d\n", x[i].dob.month);
printf("Year is %d\n", x[i].dob.year);
}
}
}

You might also like