Read and Store Roll No and Marks of 20 Students Using Array in C

Storing and accessing student records is a common use case in programming. In this article, we will explore how to read and store the roll number and marks of 20 students using array in C. This type of array-based data handling is essential in building management systems, and it’s an important concept for beginners in C programming.


C Program to Read and Store the Roll No and Marks of 20 Students Using Array

The following program uses two arrays:

  • One to store roll numbers
  • Another to store corresponding marks of 20 students
#include <stdio.h>

int main() {
int rollNo[20];
float marks[20];
int i;

// Input roll number and marks
for(i = 0; i < 20; i++) {
printf("Enter roll number of student %d: ", i + 1);
scanf("%d", &rollNo[i]);

printf("Enter marks of student %d: ", i + 1);
scanf("%f", &marks[i]);
}

// Display the data
printf("\nRoll Number\tMarks\n");
for(i = 0; i < 20; i++) {
printf("%d\t\t%.2f\n", rollNo[i], marks[i]);
}

return 0;
}

Output Example

Enter roll number of student 1: 101
Enter marks of student 1: 86.5
...
Enter roll number of student 20: 120
Enter marks of student 20: 91.0

Roll Number Marks
101 86.50
102 74.25
...
120 91.00

Explanation

This C program uses arrays to handle student data efficiently. The rollNo[20] array stores integer values for roll numbers, while the marks[20] array stores float values for student marks. We use a loop to input and display the data, showing how arrays can store and process multiple values with ease.

This approach lays the foundation for more advanced student management systems using structures and file handling in C.


Why Learn Arrays for Student Data?

Understanding how to read and store roll no and marks of 20 students using array in C builds your base for:

  • Handling bulk data
  • Looping and indexing logic
  • Real-world scenarios like report generation

Previous Article

Character Pattern in C Using Nested Loops

Next Article

Write a Program to Find Maximum Element from 1-Dimensional Array in C

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨