[go: up one dir, main page]

0% found this document useful (0 votes)
4 views16 pages

C Prog Structures

The document contains a series of programming exercises that involve creating and manipulating structures in C. Each exercise includes a specific structure definition, a program to perform operations on that structure, and sample code demonstrating the implementation. The exercises cover various topics such as student records, clock time addition, car inventory management, employee data handling, and book information retrieval.

Uploaded by

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

C Prog Structures

The document contains a series of programming exercises that involve creating and manipulating structures in C. Each exercise includes a specific structure definition, a program to perform operations on that structure, and sample code demonstrating the implementation. The exercises cover various topics such as student records, clock time addition, car inventory management, employee data handling, and book information retrieval.

Uploaded by

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

EXERCISE NO:10 NAME: M SANTHOSH KUMAR

20/05/2025 ROLL NO: 24Z361

STRUCTURES
QUESTION 1:
Create a structure STUDENT with the members: name, roll
number, course, branch, gender, and cut-off marks. Write a
program that defines an array of structures for the Struct
Student, accepts the inputs for its members, and Prints the
details of the student who has the highest cutoff mark.
CODE:
#include<stdio.h>
#include<string.h>
struct student
{
char name[700];
char rollno[500];
char course[20];
char branch[70];
char gender[70];
float mrk;
};
int main()
{
char s[100];
int a,i;
float max;
scanf("%d",&a);
struct student x[a];
for(i=0;i<a;i++)
{
scanf("%s",x[i].name);
scanf("%s",x[i].rollno);
scanf("%s",x[i].course);
scanf("%s",x[i].branch);
scanf("%s",x[i].gender);
scanf("%f",&x[i].mrk);
}
for(i=0;i<a;i++)
{
if(x[i].mrk>max)
{
max=x[i].mrk;
strcpy(s,x[i].name);
}
}
printf("The student with the highest cutoff mark is
%s.\n",s);
printf("Cutoff mark: %.2f",max);
}
OUTPUT:
QUESTION 2:
Define a structure named Clock with the members named
hours, minutes, and seconds. Create two structure variables
that represent two different clock times. Write a program to
find the sum of two clock times using a function.
CODE:
#include<stdio.h>
struct Clock
{
int hour;
int minute;
int second;
};
void clck(struct Clock x[])
{
int i,h,m,s;
h=x[0].hour+x[1].hour;
m=x[0].minute+x[1].minute;
s=x[0].second+x[1].second;
if(s>60)
{
s-=60;
m+=1;
}
if(m>60)
{
m-=60;
h+=1;
}
printf("The sum of the two clock times is: %d:%d:%d
hours.",h,m,s);
}
int main()
{
int i;
struct Clock x[2];
for(i=0;i<2;i++)
{
scanf("%d",&x[i].hour);
scanf("%d",&x[i].minute);
scanf("%d",&x[i].second);
}
clck(x);
}
OUTPUT:
QUESTION 3:
Write a program to compute the inventory for five different
car models using structures.
The structure consists of a 20-character model name, the
number of cars of each model, and the price of each car
model. Find the following details.
1) The total cost of all car models
2) Total number of cars and total cost for a particular model.
CODE:
#include<stdio.h>
#include<string.h>
struct car
{
char name[650];
int number;
int price;
};
int main()
{
int a,i,sum=0,num=0,tot=0,dh;
char s[650];
scanf("%d",&a);
struct car x[a];
for(i=0;i<a;i++)
{
scanf("%s",&x[i].name);
scanf("%d",&x[i].number);
scanf("%d",&x[i].price);
tot+=x[i].price;
}
scanf("%s",s);
printf("%d\n",tot);
for(i=0;i<a;i++)
{
if(!(strcmp(x[i].name,s)))
{
sum+=x[i].price;
num++;
}
}
printf("%d %d",num,sum);
}
OUTPUT:
QUESTION 4:
Create a structure to specify data on Employees like
Employee Number, Name, Department, Course, and Year of
joining. Assume that there are not more than 10 employees
in the company.
a. Write a function to print the names of all employees
who joined in a particular year.
b. Write a function to print the data of an employee
whose employee number is given.
CODE:
#include<stdio.h>
struct emp
{
int no;
char name[650];
char course[400];
char sub[450];
int y;
};
void names(struct emp e[],int year, int n)
{
int i;
for(i=0;i<n;i++)
{
if(e[i].y==year)
{
printf("%s\n",e[i].name);
}
else
{
printf("Year not found.\n");
}
}
}
void data(struct emp e[],int id, int n)
{
int i;
for(i=0;i<n;i++)
{
if(e[i].no==id)
{
printf("Employee Details:\n");
printf("%d\n",e[i].no);
printf("%s\n",e[i].name);
printf("%s\n",e[i].course);
printf("%s\n",e[i].sub);
printf("%d\n",e[i].y);
break;
}
else
{
printf("No information found!\n");
}
}
}
int main()
{
int n,i,year,id;
scanf("%d",&n);
struct emp e[n];
for(i=0;i<n;i++)
{
scanf("%d",&e[i].no);
scanf("%s",e[i].name);
scanf("%s",e[i].course);
scanf("%s",e[i].sub);
scanf("%d",&e[i].y);
}
scanf("%d",&year);
scanf("%d",&id);
printf("Employee Names:\n");
names(e,year,n);
data(e,id,n);
}
OUTPUT:
QUESTION 5:
Write a program to create a structure named book with
structure members' book id, book name, author name,
price, and status(1-Issued,0-Available). The user obtains
input for ‘n’ books and displays the book details based on
the given book id.
CODE:
#include<stdio.h>
struct book
{
int sno;
char name[700];
char author[700];
float price;
int status;
};
int main()
{
int a,i,p;
scanf("%d",&a);
struct book x[a];
for(i=0;i<a;i++)
{
scanf("%d",&x[i].sno);
scanf("%s",x[i].name);
scanf("%s",x[i].author);
scanf("%f",&x[i].price);
scanf("%d",&x[i].status);
}
scanf("%d",&p);
for(i=0;i<a;i++)
{
if(x[i].sno==p)
{
printf("%s ",x[i].name);
printf("%s ",x[i].author);
printf("%.2f ",x[i].price);
printf("%d ",x[i].status);
}
}
}
OUTPUT:

You might also like