This question already has an answer here:
I need to generate 5 random numbers in a range between -10 and +10. How could I do this? I've seen that one can use shuffle, malloc or even realloc, but because Iam new to C, I do not quite understand how I can make it work. If anyone can help me, I'll be grateful.
The only part of my code, it's only that I have created the array with size 5, so that I can then try to generate the random numbers.
include <stdio.h>
include <stdlib.h>
include <locale.h>
int main() {
setlocale(LC_ALL,"portuguese");
int num[5]// this will be the variable that I will use to generate random numbers.
int positive;
int negative;
return 0;
}
After generating the 5 random numbers, I need to check if they are positive or negative, I created a part of the code already, don't know if will work :
if(num[i] > 0) {
positive += 1;
}
else if(num[i] < 0 ) {
negative += 1;
}
printf("\nPositive(s) : %d ",positive);
printf("Negative(s) : %d ",negative);
How can I make all this work, by generating the 5 numbers and checking them out ?
Aucun commentaire:
Enregistrer un commentaire