Grading Students Solution
Hello, developers here is the solution for Grading Students Challenge.
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int* solve(int grades_size, int* grades){
int *result=(int *)malloc(sizeof(int)*grades_size);
int r,multi;
for(int i=0;i<grades_size;i++)
{
r=grades[i]/5;
multi=5*(r+1);
if(grades[i]>=38)
{
if(multi-grades[i]<3)
{result[i]=multi;}
else
result[i]=grades[i];
}
else
result[i]=grades[i];
}
return (result);
}
int main() {
int n;
scanf("%d", &n);
int *grades = (int *)malloc(sizeof(int) * n);
for(int grades_i = 0; grades_i < n; grades_i++){
scanf("%d",&grades[grades_i]);
}
int* result = solve(n,grades);
for(int result_i = 0; result_i < n; result_i++) {
if(result_i) {
printf("\n");
}
printf("%d", result[result_i]);
}
return 0;
}
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int* solve(int grades_size, int* grades){
int *result=(int *)malloc(sizeof(int)*grades_size);
int r,multi;
for(int i=0;i<grades_size;i++)
{
r=grades[i]/5;
multi=5*(r+1);
if(grades[i]>=38)
{
if(multi-grades[i]<3)
{result[i]=multi;}
else
result[i]=grades[i];
}
else
result[i]=grades[i];
}
return (result);
}
int main() {
int n;
scanf("%d", &n);
int *grades = (int *)malloc(sizeof(int) * n);
for(int grades_i = 0; grades_i < n; grades_i++){
scanf("%d",&grades[grades_i]);
}
int* result = solve(n,grades);
for(int result_i = 0; result_i < n; result_i++) {
if(result_i) {
printf("\n");
}
printf("%d", result[result_i]);
}
return 0;
}
Comments
Post a Comment