Problem Statement 1: Write a program for an organization (University, library, s
ID: 3790243 • Letter: P
Question
Problem Statement 1:
Write a program for an organization (University, library, shop, Kitchen etc….) that record multiple no. of entities (structure variables) data using data structure. And print it on screen using a user defined Function
Problem Statement 1: Write a program for an organization (University, library, shop, Kitchen etc....) that record multiple no. of entities (structure variables) data using data structure. And print it on screen using a user defined Function When the program is run the output might look like this "Welcome to Air University Please enter how many students data to enter? Enter student 1 data Name: Ali Rollno: 13023 CGPA: 3.5 Enter Student2data Name: Mehdi Rollno: 1322 CGPA: 3 Printing the data of all the students Student list. CGPA: 3.5 Rollno: 13023 CGPA: 3 Mehdi Rollno: 1322Explanation / Answer
Code : Just compile and run the code. I have used a struct to store the data here. All the best.
#include <stdio.h>
#include <string.h>
struct student{
char name[30];
int rollno;
float cgpa;
};
int main()
{
char line[256];
int i;
printf("Welcome to Air University ");
printf("Please enter how many students data to enter? ");
if (fgets(line, sizeof(line), stdin)) {
if (1 == sscanf(line, "%d", &i)) {
/* i can be safely used */
i = i;
}
}
int j;
struct student record[i];
for(j=0; j<i; j++){
printf("Enter student %d data",j+1);
printf(" Name :");
scanf(" %s", record[j].name);
printf("Rollno :");
scanf("%d",&record[j].rollno);
printf("CGPA :");
scanf("%f",&record[j].cgpa);
}
for(j=0; j<i; j++)
{
printf(" Records of STUDENT : %d ", j+1);
printf(" Roll no. is: %d ", record[j].rollno);
printf(" Name is: %s ", record[j].name);
printf(" CGPA is: %f ",record[j].cgpa);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.