Here we are storing a piece of student information using the structure we are taking input from Roll Number, Student Name, Student Age & Students Marks. But you can store multiple Student information as you want
Declare Structure Program For Student
Storing Student Details in Structure
Displaying Student Stored Information
Read: School Management System Project in Java With Source Code
The structure is a user-defined data type in C which allows you to combine different data types to store a particular type of record. Structure helps to construct a complex data type in a more meaningful way. It is somewhat similar to an Array. The only difference is that array is used to store a collection of similar datatypes while a structure can store a collection of any type of data.
The structure is used to represent a record. Suppose you want to store a record of a Student which consists of the student's name, address, roll number and age. You can define a structure to hold this information.
struct keyword is used to define a structure. struct define a new data type which is a collection of different type of data.
Structure Syntax
struct structure_name
{
//Statements
};
Declare Structure Program For Student
struct student
{
int roll;
char name[50];
int age;
float marks;
};
Storing Student Details in Structure
{
printf("\nRoll No: ");
scanf("%d", &(s[i].roll));
printf("Name: ");
scanf("%s", s[i].name);
printf("Age: ");
scanf("%d", &(s[i].age));
printf("Marks: ");
scanf("%f", &(s[i].marks));
}
Displaying Student Stored Information
printf("\n\nDisplay Student Details:\n");
for (i = 0; i < n; i++)
{
printf("\nRoll No: %d", s[i].roll);
printf("\nName: %s", s[i].name);
printf("\nAge: %d", s[i].age);
printf("\nMarks: %f", s[i].marks);
printf("\n\n");
}
Read: School Management System Project in Java With Source Code
Structure Program For Student Details in C Code
#include <stdio.h>
/*C Program to Store Information of 10(N) Students Using Structure*/
struct student
{
int roll;
char name[50];
int age;
float marks;
};
int main()
{
int i, n;
printf("\nEnter the Total Number Of Student: ");
scanf("%d", &n);
struct student s[n];
printf("\nEnter Student Details (Enter Marks in Float Ie. 78.00):\n");
for (i = 0; i < n; i++)
{
printf("\nEnter Student Roll No: ");
scanf("%d", &(s[i].roll));
printf("Enter Student Name: ");
scanf("%s", s[i].name);
printf("Enter Student Age: ");
scanf("%d", &(s[i].age));
printf("Enter Student Marks: ");
scanf("%f", &(s[i].marks));
}
printf("\n\nDisplay Student Details:\n");
for (i = 0; i < n; i++)
{
printf("\nStudent Roll No: %d", s[i].roll);
printf("\nStudent Name: %s", s[i].name);
printf("\nStudent Age: %d", s[i].age);
printf("\nStudent Marks: %f", s[i].marks);
printf("\n\n");
}
return 0;
}
What Is Structure
The structure is a user-defined data type in C which allows you to combine different data types to store a particular type of record. Structure helps to construct a complex data type in a more meaningful way. It is somewhat similar to an Array. The only difference is that array is used to store a collection of similar datatypes while a structure can store a collection of any type of data.
The structure is used to represent a record. Suppose you want to store a record of a Student which consists of the student's name, address, roll number and age. You can define a structure to hold this information.
Defining a Structure
struct keyword is used to define a structure. struct define a new data type which is a collection of different type of data.
Structure Syntax
struct structure_name
{
//Statements
};
0 Comments: