Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- int main()
- {
- int num_of_students=0;
- char input[100];
- int id[500];
- char names[500][50];
- double marks[500];
- double average_marks = 0.0;
- printf("Please enter the total number of students : ");
- gets(input); // Taking user input for number of students
- num_of_students = atoi(input); // converting char to int
- for(int i=0;i<num_of_students;i++)
- {
- gets(input);
- char int_temp[20];
- int j;
- for(j=0;input[j]!=',';j++)
- {
- int_temp[j] = input[j];
- }
- int_temp[j] = '\0';
- id[i] = atoi(int_temp);
- j++;
- int k=0;
- for(;input[j]!=',';j++)
- {
- names[i][k] = input[j];
- k++;
- }
- names[i][k] = '\0';
- j++;
- char double_temp[20];
- k=0;
- for(;input[j]!='\0';j++)
- {
- double_temp[k++] = input[j];
- }
- double_temp[k] = '\0';
- marks[i] = atof(double_temp);
- }
- for(int i=0;i<num_of_students;i++)
- {
- average_marks += marks[i];
- printf("Student id : %d ,",id[i]);
- printf("Student name : ");
- for(int k=0;names[i][k]!='\0';k++)
- {
- if(names[i][k] >= 'a' && names[i][k] <= 'z')
- {
- printf("%c",names[i][k]-32);
- }
- else
- {
- printf("%c",names[i][k]);
- }
- }
- printf(", Student marks : %lf \n",marks[i]);
- }
- average_marks /= num_of_students;
- printf("Average marks : %lf\n",average_marks);
- while(1)
- {
- printf("Please enter a key for searching or press q/Q for exit : ");
- gets(input);
- if(input[1] == '\0' && (input[0] == 'q' || input[0] == 'Q'))
- {
- printf("Exiting the program");
- break;
- }
- double average = 0.0;
- int records_found = 0;
- for(int i=0;i<num_of_students;i++)
- {
- if(strstr(names[i],input) != NULL)
- {
- records_found++;
- average += marks[i];
- printf("Student id : %d ,",id[i]);
- printf("Student name : ");
- for(int k=0;names[i][k]!='\0';k++)
- {
- if(names[i][k] >= 'a' && names[i][k] <= 'z')
- {
- printf("%c",names[i][k]-32);
- }
- else
- {
- printf("%c",names[i][k]);
- }
- }
- printf(", Student marks : %lf \n",marks[i]);
- }
- }
- if(records_found != 0)
- average /= records_found;
- printf("Average marks : %lf\n",average);
- }
- return 0;
- }
- Ouput :
- Please enter the total number of students : 5
- 1,amit sharma,97
- 2,shikar dhawan,95
- 3,rohit sharma,56
- 4,virat kohli,46
- 5,mahendra singh dhoni,99
- Student id : 1 ,Student name : AMIT SHARMA, Student marks : 97.000000
- Student id : 2 ,Student name : SHIKAR DHAWAN, Student marks : 95.000000
- Student id : 3 ,Student name : ROHIT SHARMA, Student marks : 56.000000
- Student id : 4 ,Student name : VIRAT KOHLI, Student marks : 46.000000
- Student id : 5 ,Student name : MAHENDRA SINGH DHONI, Student marks : 99.000000
- Average marks : 78.600000
- Please enter a key for searching or press q/Q for exit : d
- Student id : 2 ,Student name : SHIKAR DHAWAN, Student marks : 95.000000
- Student id : 5 ,Student name : MAHENDRA SINGH DHONI, Student marks : 99.000000
- Average marks : 97.000000
- Please enter a key for searching or press q/Q for exit : q
- Exiting the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement