Imran1107048

Struct

Mar 24th, 2021 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. struct student
  5. {
  6. char name[20];
  7. int age;
  8. float weight;
  9. float height;
  10. };
  11.  
  12. void printAllStudents(struct student students[])
  13. {
  14. printf("All Students Information:\n");
  15. for(int i=0;i<5;i++){
  16. printf("%s %d %f %f\n",students[i].name, students[i].age, students[i].weight, students[i].height);
  17. }
  18. }
  19.  
  20. void findMaxStudent(struct student students[])
  21. {
  22. int mx = 0;
  23. for(int i=0;i<5;i++){
  24. if(mx < students[i].age){
  25. mx = students[i].age;
  26. }
  27. }
  28.  
  29. printf("\n\nMaximum Age Student:\n");
  30. for(int i=0;i<5;i++){
  31. if(mx == students[i].age){
  32. printf("%s %d %f %f\n",students[i].name, students[i].age, students[i].weight, students[i].height);
  33. }
  34. }
  35. }
  36.  
  37. void changeName(struct student students[], char newName[], int index)
  38. {
  39. printf("\n\nPrint the change name:\n");
  40. printf("%s %d %f %f\n",newName, students[index].age, students[index].weight, students[index].height);
  41. }
  42.  
  43. int main()
  44. {
  45. struct student students[5] = {{"Jamil", 33, 66.5, 5.8}, {"Habil",
  46. 12, 30.7, 5.1},
  47. {"Kabir", 45, 79.1, 6.1},
  48. {"Nafis", 27, 71, 5.11},
  49. {"Arif", 22, 62, 5.8}};
  50.  
  51. printAllStudents(students);
  52. findMaxStudent(students);
  53. changeName(students, "Aman", 1);
  54.  
  55. return 0;
  56. }
  57.  
Add Comment
Please, Sign In to add comment