## Algorithm

Problem Name: Algorithms - Grading Students

In this HackerRank Functions in Algorithms - Java programming problem solution,

HackerLand University has the following grading policy:

• Every student receives a grade in the inclusive range from 0 to 100.

Sam is a professor at the university and likes to round each student’s grade according to these rules:

• If the difference between the grade and the next multiple of 5 is less than 3, round grade up to the next multiple of 5.
• If the value of grade is less than 38, no rounding occurs as the result will still be a failing grade.

Examples

•  grade = 84 round to 85 (85 – 84 is less than 3)
•  grade = 29 do not round (result is less than 40)
•  grade do not round (60 – 57 is 3 or higher)

Given the initial value of  for each of Sam’s  students, write code to automate the rounding process.

Function Description

Complete the function gradingStudents in the editor below.

Returns

• int[n]: the grades after rounding as appropriate

Input Format

The first line contains a single integer,n, the number of students.

Each line i of the n subsequent lines contains a single integer, grade[i].

Constraints

• 1<=n<=60

Sample Input 0

```4

73

67

38

33```

Sample Output 0

```75

67

40

33```

## Code Examples

### #1 Code Example with C Programming

```Code - C Programming```

``````
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
int n;
scanf("%d",&n);
for(int a0 = 0; a0  <  n; a0++){
float go;
go = ceil(go);
go = go * 5;
//printf("%f\n", go);
}
}

}
return 0;
}
``````
Copy The Code &

### #2 Code Example with C++ Programming

```Code - C++ Programming```

``````
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for(int i = 0; i  <  n; i++)
{
cin>>a[i];
}
for(int i = 0; i  <  n; i++)
{
if(a[i] >= 38){
if((a[i]%5) == 3)
{
a[i] = a[i]+2;
}
if((a[i]%5) == 4)
{
a[i] = a[i] + 1;}
}
}
for(int i = 0; i < n; i++>
{
cout << a[i] << endl;
}
return 0;
}
``````
Copy The Code &

### #3 Code Example with Java Programming

```Code - Java Programming```

``````
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

for (int i = 0; i  <  grades.length; i++) {
if (nextMultipleOfFive - grades[i]  <  3) {
}
}
}

}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
}
for (int i = 0; i  <  result.length; i++) {
System.out.print(result[i] + (i != result.length - 1 ? "\n" : ""));
}
System.out.println("");

}
}
``````
Copy The Code &

### #4 Code Example with Javascript Programming

```Code - Javascript Programming```

``````
'use strict';

const fs = require('fs');

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', function(inputStdin) {
inputString += inputStdin;
});

process.stdin.on('end', function() {
inputString = inputString.split('\n');

main();
});

return inputString[currentLine++];
}

/*
* Complete the 'gradingStudents' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts INTEGER_ARRAY grades as parameter.
*/

// the problem is n neareste whole number.
//const roundNumber=Math.abs((value%5)-5)+value;
const roundNumber=Math.ceil(value/5)*5;
return (roundNumber-value) < 3 && roundNumber>=40?roundNumber:value
})
}

function main() {
const ws = fs.createWriteStream(process.env.OUTPUT_PATH);

for (let i = 0; i  <  gradesCount; i++) {
}

ws.write(result.join('\n') + '\n');

ws.end();
}
``````
Copy The Code &

### #5 Code Example with C# Programming

```Code - C# Programming```

``````
using System;

class Solution
{
{
for (int i = 0; i  <  grades.Length; i++)
{
if (item >= 38)
{
var diff = 5 - (item % 5);
if (diff  <  3)
}
}

}

static void Main(String[] args)
{

Console.WriteLine(String.Join("\n", result));
}
}
``````
Copy The Code &

### #6 Code Example with Python Programming

```Code - Python Programming```

``````
import sys
import math

# Complete this function
toReturn = ""
if(grade >= 38 and 5-c < 3 and c != 0>:
else:

n = int(input().strip())
``````
Copy The Code &

### #7 Code Example with PHP Programming

```Code - PHP Programming```

``````
= 38) {
if (\$m == 3) {
}
if (\$m == 4) {
}
}
}
}

\$fptr = fopen(getenv("OUTPUT_PATH"), "w");

\$__fp = fopen("php://stdin", "r");

fscanf(\$__fp, "%d\n", \$n);