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>
#include<string>
using namespace std;
int numberStudents(int* tests,int totalNumberStudents){
int counter=0;
for(int i=0;i<totalNumberStudents;i++){
if(tests[i]>=20){
counter++;
}
}
return counter;
}
int main(){
int totalNumberStudents;
int* tests;
cout<<"Enter the total number of students who took the test: ";
cin>>totalNumberStudents;
tests=new int[totalNumberStudents];
for(int i=0;i<totalNumberStudents;i++){
cout<<"Enter the test "<<(i+1)<<": ";
cin>>tests[i];
}
cout<<"\nThe number of students who have scored marks greater than 20 in an exam is: "<<numberStudents(tests,totalNumberStudents)<<"\n\n";
delete[] tests;
cin>>totalNumberStudents;
return 0;
}
Comments
Leave a comment