0% found this document useful (0 votes)
26 views6 pages

Rishi

Uploaded by

mushkerishik
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)
26 views6 pages

Rishi

Uploaded by

mushkerishik
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/ 6

DATA STRUCTURES LAB

WEEK -1
NAME: M.RISHIK

ROLL NO.: 22R21A04H3

1)Problem statement: Write a C program to read the name, Roll number, year
and marks of three subjects of a student and print the student the name, roll
number, and average marks of the student using structures.

Aim: To Write a C program to read the name, Roll number, year and marks of
three subjects of a student and print the student the name, roll number, and
average marks of the student using structures.

Syntax: struct structure name


{
datatype Variable1;
datatype Variable2;
…..
……
};

PROGRAM :
#include <stdio.h>
struct Student {
char name[50];
int rollNumber;
int year;
float marks,s1,s2,s3;
};
int main() {
struct Student s;
printf("Enter Student Name: ");
scanf("%s", s.name);
printf("Enter Roll Number: ");
scanf("%d", &s.rollNumber);
printf("Enter Year: ");
scanf("%d", &s.year);
printf("Enter Marks for three subjects:\n");
scanf("%f",&s.s1);
scanf("%f",&s.s2);
scanf("%f",&s.s3);
s.marks=(s.s1+s.s2+s.s3)/3;
printf("\nStudent Information:\n");
printf("Name: %s\n", s.name);
printf("Roll Number: %d\n", s.rollNumber);
printf("Year: %d\n", s.year);
printf("Average Marks: %.2f\n",s.marks);
return 0;
}

Testcase:

2)Problem statement:Write a C program to store name, roll number, year and


marks of three subjects of n students and print the student the name, roll
number, average and grade based on average marks of the student using
structures.

Aim : To Write a C program to store name, roll number, year and marks of three
subjects of n students and print the student the name, roll number, average and
grade based on average marks of the student using structures.

Syntax: struct structurename


{
datatype Variable1;
datatype Variable2;
…..
……
};
PROGRAM :
#include <stdio.h>
struct Student {
char name[50];
int rollNumber, year;
float Marks,s1,s2,s3;
char grade;
};
char GRADE(float average) {
return average >= 90 ? 'A' : average >= 80 ? 'B' : average >= 70 ? 'C' : average >= 60 ? 'D' : 'F';
}
int main() {
int n;
printf("Enter the number of students: ");
scanf("%d", &n);
struct Student s[n];
for (int i = 0; i < n; i++) {
printf("Enter details for Student %d:\n", i + 1);
printf("Name: ");
scanf("%s", s[i].name);
printf("Roll Number: ");
scanf("%d", &s[i].rollNumber);
printf("Year: ");
scanf("%d", &s[i].year);
printf("Enter Marks for three subjects: ");
scanf("%f",&s[i].s1);
scanf("%f",&s[i].s2);
scanf("%f",&s[i].s3);
s[i].Marks=(s[i].s1+s[i].s2+s[i].s3)/3;
s[i].grade = GRADE(s[i].Marks);}
printf("\nStudent Information:\n");
for (int i = 0; i < n; i++) {
printf("Student %d:\nName: %s\nRoll Number: %d\nYear: %d\nAverage Marks: %.2f\nGrade: %c\n\n",
i + 1, s[i].name, s[i].rollNumber, s[i].year, s[i].Marks, s[i].grade);}
return 0;}

Testcase:
3)Problem statement:Write a C Program to read student name, roll number and
average marks of a student using structure and within another structure read
date of birth of a student as day, month and year. Print the student’s name,
roll number, day of birth and average marks of a student.

Aim : To Write a C Program to read student name, roll number and average marks
of a student using structure and within another structure read date of birth of
a student as day, month and year. Print the student’s name, roll number, day of
birth and average marks of a student.

Syntax: struct structurename


{
datatype Variable1;
datatype Variable2;
…..
……
};

PROGRAM :
#include <stdio.h>

struct DateOfBirth {
int day, month, year;
};

struct Student {
char name[50];
int rollNumber;
float averageMarks;
struct DateOfBirth dob;
};

int main() {
struct Student S;

printf("Enter Name, Roll Number, Date of Birth (day month year), and Average Marks: ");
scanf("%s %d%d %d %d %f", S.name, &S.rollNumber, &S.dob.day, &S.dob.month, &S.dob.year, &S.averageMarks);

printf("\nStudent Information:\nName: %s\nRoll Number: %d\nDate of Birth: %d/%d/%d\nAverage Marks: %.f\n",


S.name, S.rollNumber, S.dob.day, S.dob.month, S.dob.year, S.averageMarks);

return 0;
}

Testcase:
4)Problem statement:Write a C program to store name, roll number, year and
marks of three subjects of n students and print the student the name, roll
number, average and grade based using pointer variable.

Aim : To Write a C program to store name, roll number, year and marks of three
subjects of n students and print the student the name, roll number, average and
grade based using pointer variable.
Syntax:struct Structure name* Pointer
Input: char name[50];

int rollno;

int year;

float marks[3];

float average;

char grade;

Output: Student Information:

Name: TEJESH
Roll Number: 45
Year: 2005
Average Marks: 92.333336
Grade: A

PROGRAM :
#include <stdio.h> float average;

struct Student { char grade;};

char name[50]; int avg(struct Student* s) {

int rollno; float sum = 0;

int year; for (int i = 0; i < 3; i++) {

float marks[3]; sum=sum+s->marks[i];}


s->average = sum / 3.0; printf("Name: ");

if (s->average >= 90.0) { scanf("%s", s[i].name);

s->grade = 'A'; printf("Roll Number: ");

} else if (s->average >= 70.0) { scanf("%d", &s[i].rollno);

s->grade = 'B'; } else if (s->average >= 50.0) { printf("Year: ");

s->grade = 'c'; scanf("%d", &s[i].year);

} else { printf("Enter marks:\n");

s->grade = 'F';}} for (int j = 0; j < 3; j++) {

int main() {int n; printf("Subject %d: ", j + 1);

printf("Enter the number of students: "); scanf("%f", &s[i].marks[j]);}

scanf("%d", &n); avg(&s[i]);}

if (n <= 0) { printf("\nStudent Information:\n");

printf("Invalid \n"); for (int i = 0; i < n; i++) {

return 1;} printf("\nName: %s\nRoll Number: %d\nYear: %d\nAverage


Marks: %f\nGrade: %c\n",
struct Student s[n];
s[i].name, s[i].rollno, s[i].year, s[i].average, s[i].grade);}
for (int i = 0; i < n; i++) {
return 0;}
printf("\nEnter details %d:\n", i + 1);

Testcase:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy