How to Use C Program to Store Information of 10 Students Using Array?
Are you a beginner in programming looking to store data of multiple students in C programming? You are in the right place. In this article, we will take you through the process of storing information of 10 students using an array in C programming.
Introduction
Arrays are an essential part of C programming, and they allow you to store multiple variables of the same data type. In this case, we will focus on how to store information of 10 students using C programming.
Setting Up the Code
To start, we need to set up the code by defining the variables we will use for the student’s information. We will create the array `students` to hold the information and assign the variable `i` to loop through the array.
“`
#include
void main()
{
int i, students[10];
}
“`
Storing Student Information
Now that we have set up the code, we need to move on to store the student’s information. We will use a loop to store the information of each student one by one.
“`
for(i=0;i<10;i++)
{
printf("Enter Roll No, Name and Marks of Student %d: ", i+1);
scanf("%d %s %f",&students[i].roll, &students[i].name, &students[i].marks);
}
```
In the above code, we are using `scanf()` to read the information of each student and then store it in the `students` array.
Retrieving Student Information
Next, we will retrieve the stored information of each student using another loop.
“`
for(i=0;i<10;i++)
{
printf("\nRoll no.: %d", students[i].roll);
printf("\nName: %s", students[i].name);
printf("\nMarks: %.2f\n\n", students[i].marks);
}
```
Using `printf()`, we will display the stored information of each student one by one in the above code.
Putting It All Together
The complete code to store and retrieve information of 10 students using an array is shown below.
“`
#include
struct student
{
int roll;
char name[50];
float marks;
} students[10];
int main()
{
int i;
for(i=0;i<10;i++) { printf("Enter Roll No, Name and Marks of Student %d: ", i+1); scanf("%d %s %f",&students[i].roll, &students[i].name, &students[i].marks); } printf("\n\n*************DISPLAYING INFORMATION*************\n\n"); for(i=0;i<10;i++) { printf("\nRoll no.: %d", students[i].roll); printf("\nName: %s", students[i].name); printf("\nMarks: %.2f\n\n", students[i].marks); } return 0; } ```
Conclusion
In conclusion, storing and retrieving information of multiple students using an array in C programming is a straightforward process. By following the steps outlined above and using the example code provided, you can easily store and retrieve data of 10 students. With practice, you can even store data of multiple students without any limit.
(Note: Do you have knowledge or insights to share? Unlock new opportunities and expand your reach by joining our authors team. Click Registration to join us and share your expertise with our readers.)
Speech tips:
Please note that any statements involving politics will not be approved.