Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- // struct book {
- // char name[40];
- // int publishYear;
- // };
- // int main() {
- // // datatype variable name;
- // struct book BookOne;
- // printf("Enter a book name:\n");
- // fgets(BookOne.name, 40, stdin);
- // printf("Enter The book's publish year\n");
- // scanf("%d", &BookOne.publishYear);
- // printf("The book name is %s", BookOne.name);
- // printf("Publish Year: %d\n", BookOne.publishYear);
- // }
- // structure of array
- struct student {
- char studentName[40];
- int id;
- double marks;
- };
- int main() {
- int totalStudent;
- printf("Enter the number of total student\n");
- scanf("%d", &totalStudent);
- struct student Student[totalStudent];
- int i;
- // for taking input from the user
- for (i = 0; i < totalStudent; i++) {
- printf("Student information no: %d\n", i + 1);
- printf("Enter student name:\n");
- fflush(stdin);
- fgets(Student[i].studentName, 40, stdin);
- fflush(stdout);
- printf("Enter student id:\n");
- scanf("%d", &Student[i].id);
- printf("Enter student marks:\n");
- scanf("%lf", &Student[i].marks);
- printf("\n");
- }
- // Print the information
- for (i = 0; i < totalStudent; i++) {
- printf("Name: %s", Student[i].studentName);
- printf("ID: %d\n", Student[i].id);
- printf("Marks: %.2lf\n", Student[i].marks);
- printf("\n");
- }
- // Find the maximum number of a student
- double max = 0;
- for (i = 0; i < totalStudent; i++) {
- if(Student[i].marks > max) {
- max = Student[i].marks;
- }
- }
- printf("The maximum number of a student is %lf\n", max);
- // print the information who has the maximum marks
- int index = 0;
- max = 0;
- for (i = 0; i < totalStudent; i++) {
- if(Student[i].marks > max) {
- max = Student[i].marks;
- index = i;
- }
- }
- printf("Name: %s", Student[index].studentName);
- printf("ID: %d\n", Student[index].id);
- printf("Marks: %.2lf\n", Student[index].marks);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement