hey guys i need help with a simple code. i'm super new to coding and i'm pretty sure sorting randomly generated numbers have not been taught by my profs yet. however, an exercise requires me to use my current skills (loops and decision making) to generate 50 random numbers within 4 to 6 and then sort it into 4 groups with intervals of 0.5 (eg 4-4.5, 4.5-5, etc etc). i managed to generate 50 numbers within the range but i have absolutely no idea how to continue from here. also, i have yet to learn arrays so i'm not sure if i can use it in the code. are there any other ways to do that?
in my defense, i know nothing about codes AT ALL. and i would appreciate if someone would help me. i've been stuck for 3 days and i'm terribly desperate to get this done.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int i = 1, max = 50, random_num, student_height;
srand((unsigned) time(NULL));
while (i <= max)
{
random_num = rand()%200+400;
double(student_height) = random_num / 100.0;
printf("The height of a random student is %.2lf \n", student_height);
i++;
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire