1. Write a function accepts list of marks of students and counts the number of students who have scored marks greater than 20 in an exam out of 30. The total number of students who took the test is to be entered from the keyboard.
#include <iostream>
void Write(int n)
{
int counts{ 0 };
int mark{ 0 };
for (int i = 1; i <= n; i++)
{
std::cout << "Enter the mark of " << i << " student: ";
std::cin >> mark;
if (mark > 20 && mark <= 30)
counts++;
}
std::cout << "The number of students who have scored marks greater than 20 in an exam out of 30: ";
std::cout << counts;
}
int main()
{
int n;
std::cout <<"Enter the number of students: ";
std::cin >> n;
Write(n);
return 0;
}
Comments
Leave a comment