++C
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n;
cout << "Enter the number of grades: ";
cin >> n;
vector<int> grades(n);
cout << "Enter the grades:" << endl;
for (int i = 0; i < n; i++) {
cin >> grades[i];
}
int max_grade = *max_element(grades.begin(), grades.end());
vector<int> max_indices;
for (int i = 0; i < n; i++) {
if (grades[i] == max_grade) {
max_indices.push_back(i);
}
}
cout << "The maximum grade is " << max_grade << ", which appears at the following indices: ";
for (int i = 0; i < max_indices.size(); i++) {
cout << max_indices[i] << " ";
}
return 0;
}
#C
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
Console.Write("Enter the number of grades: ");
int n = int.Parse(Console.ReadLine());
List<int> grades = new List<int>();
Console.WriteLine("Enter the grades:");
for (int i = 0; i < n; i++) {
grades.Add(int.Parse(Console.ReadLine()));
}
int max_grade = grades.Max();
List<int> max_indices = new List<int>();
for (int i = 0; i < n; i++) {
if (grades[i] == max_grade) {
max_indices.Add(i);
}
}
Console.Write("The maximum grade is " + max_grade + ", which appears at the following indices: ");
foreach (int index in max_indices) {
Console.Write(index + " ");
}
}
}