Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. int main()
  6. {
  7. int num_of_students=0;
  8. char input[100];
  9. int id[500];
  10. char names[500][50];
  11. double marks[500];
  12. double average_marks = 0.0;
  13.  
  14. printf("Please enter the total number of students : ");
  15. gets(input); // Taking user input for number of students
  16.  
  17. num_of_students = atoi(input); // converting char to int
  18.  
  19. for(int i=0;i<num_of_students;i++)
  20. {
  21. gets(input);
  22.  
  23. char int_temp[20];
  24. int j;
  25. for(j=0;input[j]!=',';j++)
  26. {
  27. int_temp[j] = input[j];
  28. }
  29. int_temp[j] = '\0';
  30. id[i] = atoi(int_temp);
  31. j++;
  32. int k=0;
  33. for(;input[j]!=',';j++)
  34. {
  35. names[i][k] = input[j];
  36. k++;
  37. }
  38. names[i][k] = '\0';
  39. j++;
  40.  
  41. char double_temp[20];
  42. k=0;
  43. for(;input[j]!='\0';j++)
  44. {
  45. double_temp[k++] = input[j];
  46. }
  47. double_temp[k] = '\0';
  48. marks[i] = atof(double_temp);
  49.  
  50. }
  51.  
  52. for(int i=0;i<num_of_students;i++)
  53. {
  54. average_marks += marks[i];
  55.  
  56. printf("Student id : %d ,",id[i]);
  57. printf("Student name : ");
  58. for(int k=0;names[i][k]!='\0';k++)
  59. {
  60. if(names[i][k] >= 'a' && names[i][k] <= 'z')
  61. {
  62. printf("%c",names[i][k]-32);
  63. }
  64. else
  65. {
  66. printf("%c",names[i][k]);
  67. }
  68. }
  69.  
  70. printf(", Student marks : %lf \n",marks[i]);
  71. }
  72.  
  73. average_marks /= num_of_students;
  74. printf("Average marks : %lf\n",average_marks);
  75.  
  76.  
  77. while(1)
  78. {
  79. printf("Please enter a key for searching or press q/Q for exit : ");
  80. gets(input);
  81.  
  82. if(input[1] == '\0' && (input[0] == 'q' || input[0] == 'Q'))
  83. {
  84. printf("Exiting the program");
  85. break;
  86. }
  87. double average = 0.0;
  88. int records_found = 0;
  89.  
  90. for(int i=0;i<num_of_students;i++)
  91. {
  92. if(strstr(names[i],input) != NULL)
  93. {
  94. records_found++;
  95. average += marks[i];
  96.  
  97. printf("Student id : %d ,",id[i]);
  98. printf("Student name : ");
  99. for(int k=0;names[i][k]!='\0';k++)
  100. {
  101. if(names[i][k] >= 'a' && names[i][k] <= 'z')
  102. {
  103. printf("%c",names[i][k]-32);
  104. }
  105. else
  106. {
  107. printf("%c",names[i][k]);
  108. }
  109. }
  110.  
  111. printf(", Student marks : %lf \n",marks[i]);
  112. }
  113.  
  114. }
  115. if(records_found != 0)
  116. average /= records_found;
  117. printf("Average marks : %lf\n",average);
  118. }
  119.  
  120. return 0;
  121. }
  122.  
  123. Ouput :
  124.  
  125. Please enter the total number of students : 5
  126. 1,amit sharma,97
  127. 2,shikar dhawan,95
  128. 3,rohit sharma,56
  129. 4,virat kohli,46
  130. 5,mahendra singh dhoni,99
  131. Student id : 1 ,Student name : AMIT SHARMA, Student marks : 97.000000
  132. Student id : 2 ,Student name : SHIKAR DHAWAN, Student marks : 95.000000
  133. Student id : 3 ,Student name : ROHIT SHARMA, Student marks : 56.000000
  134. Student id : 4 ,Student name : VIRAT KOHLI, Student marks : 46.000000
  135. Student id : 5 ,Student name : MAHENDRA SINGH DHONI, Student marks : 99.000000
  136. Average marks : 78.600000
  137. Please enter a key for searching or press q/Q for exit : d
  138. Student id : 2 ,Student name : SHIKAR DHAWAN, Student marks : 95.000000
  139. Student id : 5 ,Student name : MAHENDRA SINGH DHONI, Student marks : 99.000000
  140. Average marks : 97.000000
  141. Please enter a key for searching or press q/Q for exit : q
  142. Exiting the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement