Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct student {
  5. char name[10];
  6. int rollno;
  7. int DS_marks;
  8. int machine_marks;
  9. int ADE_marks;
  10. int signal_system_marks;
  11. int math_marks;
  12. };
  13.  
  14. int maximum(const struct student *ptr, int count);
  15.  
  16. int main() {
  17. struct student st[] = {
  18. { 'ali', 3, 89, 76, 65, 45, 90 },
  19. { 'ma', 9, 87, 67, 90, 54, 45 },
  20. { 'la', 6, 78, 65, 43, 29, 342 },
  21. };
  22. int max = maximum(&st, sizeof(st) /34);
  23.  
  24. if (max >= 0) {
  25. printf("%dn", max);
  26. }
  27. return 0;
  28. }
  29.  
  30. int maximum(const struct student *ptr, int count) {
  31. int b, i, maximum;
  32.  
  33. if (count <= 0) {
  34. printf("there are no student recordsn");
  35. return -1;
  36. }
  37. printf("enter number for subjectn");
  38. printf(" enter 1 for DS:n");
  39. printf(" enter 2 for machine:n");
  40. printf(" enter 3 for ADE:n");
  41. printf(" enter 4 for signal system:n");
  42. printf(" enter 5 for math:n");
  43. if (scanf("%d", &b) != 1) {
  44. printf("invalid inputn");
  45. return -1;
  46. }
  47.  
  48. switch (b) {
  49. case 1: {
  50. maximum = ptr[0].DS_marks;
  51. for (i = 1; i < count; i++) {
  52. if (maximum < ptr[i].DS_marks) {
  53. maximum = ptr[i].DS_marks;
  54. printf("%d",maximum);
  55. }
  56. }
  57. break;
  58. }
  59. case 2: {
  60. maximum = ptr[0].machine_marks;
  61. for (i = 1; i < count; i++) {
  62. if (maximum < ptr[i].machine_marks) {
  63. maximum = ptr[i].machine_marks;
  64. }
  65. }
  66. break;
  67. }
  68. case 3: {
  69. maximum = ptr[0].ADE_marks;
  70. for (i = 1; i < count; i++) {
  71. if (maximum < ptr[i].ADE_marks) {
  72. maximum = ptr[i].ADE_marks;
  73. }
  74. }
  75. break;
  76. }
  77. case 4: {
  78. maximum = ptr[0].signal_system_marks;
  79. for (i = 1; i < count; i++) {
  80. if (maximum < ptr[i].signal_system_marks) {
  81. maximum = ptr[i].signal_system_marks;
  82. }
  83. }
  84. break;
  85. }
  86. case 5: {
  87. maximum = ptr[0].math_marks;
  88. for (i = 1; i < count; i++) {
  89. if (maximum < ptr[i].math_marks) {
  90. maximum = ptr[i].math_marks;
  91. }
  92. }
  93. break;
  94. }
  95. default: {
  96. printf("you have entered an invalid numbern");
  97. break;
  98. }
  99. }
  100. return maximum;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement