Problem 32

author
By Supreme2023-03-15
Problem Statement :
Write a C program to read and store the roll no and marks of 20 students using array.
Code:

#include <stdio.h>

int main(){

//32. Write a C program to read and store the roll no and marks of 20 students using array.

printf("\tMarks-Entry");
printf("\n====================================");
int students,subjects,i,j;

printf("\n\nEnter The Number Of Students : ");
scanf("%d",&students);

printf("\nENter The Number Of Subjects : ");
scanf("%d",&subjects);

int marks[students][subjects+1];

for(i=0;i<students;i++){
printf("\n\nEnter Roll No. : ");
scanf("%d",&marks[i][0]);

for(j=0;j<subjects;j++){
printf("\nEnter Marks Of Subject [%d] : ",j+1);
scanf("%d",&marks[i][j+1]);
}
}


for(i=0;i<students;i++){

printf("\n\nRoll No. : %d",marks[i][0]);

for(j=0;j<subjects;j++){
printf("\nMarks Of Subject [%d] : %d",j+1,marks[i][j+1]);

}
}

return 0;
}

Description :
  • This program is used to read and store the roll number and marks of 20 students using a 2D array.
  • The program starts by including the standard input/output library.
  • The main function is defined and the program asks the user to input the number of students and the number of subjects.
  • A 2D array called "marks" is declared with the size of "students" rows and "subjects+1" columns. The "+1" is added to store the roll number of each student.
  • Using two nested for loops, the program prompts the user to input the roll number and marks of each student.
  • After the marks are entered, the program prints the roll number and marks of each student using two nested for loops.
  • The program ends with returning 0 to indicate successful completion of the program.
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.