fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int N;
  6. cout << "Enter number of students: ";
  7. cin >> N;
  8.  
  9. int grades[100]; // assuming max 100 students
  10. cout << "Enter " << N << " grades: ";
  11. for (int i = 0; i < N; i++) {
  12. cin >> grades[i];
  13. }
  14.  
  15. // Display all grades
  16. cout << "\nGrades entered: ";
  17. for (int i = 0; i < N; i++) {
  18. cout << grades[i] << " ";
  19. }
  20. cout << endl;
  21.  
  22. // Find highest and lowest
  23. int highest = grades[0];
  24. int lowest = grades[0];
  25.  
  26. for (int i = 1; i < N; i++) {
  27. if (grades[i] > highest) highest = grades[i];
  28. if (grades[i] < lowest) lowest = grades[i];
  29. }
  30.  
  31. cout << "Highest grade: " << highest << endl;
  32. cout << "Lowest grade: " << lowest << endl;
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5284KB
stdin
5
78 94 85 86 47
stdout
Enter number of students: Enter 5 grades: 
Grades entered: 78 94 85 86 47 
Highest grade: 94
Lowest grade: 47