Structure in C for DS LAB
Structure in C for DS LAB
#include <stdio.h>
struct Date {
int day;
int month;
int year;
};
int main() {
today.day = 3;
today.month = 11;
today.year = 2024;
return 0;
}
2.Defining a Structure for a Student
Problem: Create a structure to store information about a student (name, age, and grade).
#include <stdio.h>
#include <string.h>
struct Student {
char name[50];
int age;
float grade;
};
int main() {
strcpy(student1.name, "Alice");
student1.age = 20;
student1.grade = 88.5;
return 0;
}
3.Array of Structures
#include <stdio.h>
#include <string.h>
struct Student {
char name[20];
int age;
float grade;
};
int main() {
printf("Enter name, age, and grade for student %d: ", i + 1);
}
// Display the information
printf("\nStudent Information:\n");
return 0;
Problem: Define a structure for a book that contains a nested structure for the author.
#include <stdio.h>
#include <string.h>
struct Author {
char name[20];
char nationality[20];
};
struct Book {
char title[100];
struct Author author;
int year;
};
int main() {
struct Book book;
return 0;
}
#include <stdio.h>
#include <string.h>
struct Student {
char name[50];
int age;
float grade;
};
int main() {
struct Student student;
strcpy(student.name, "Bob");
student.age = 21;
student.grade = 75.0;
return 0;
}