#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(NULL));
for(int i = 0; i < 200; i++){
printf("%d\n", rand() % 1000);
}
int num = 123; // Playing around trying to figure out how to split a single number.
printf("%d\n", num % 10);
printf("%d\n", num / 10 % 10);
printf("%d\n", num / 100 % 10);
return 0;
}
I am trying to generate 200 random numbers between 0-999, split them into digits and get a frequency count of each digit without using any arrays. I played around and figured out how to split a single number (in reverse order) and how to generate the random numbers. Now how do I split all 200 numbers and store those digits in variables I can get a count with? Do I want three variables maybe named digit1, digit2, digit3?
Note: This is for homework so I'm not allowed to use arrays and must use a switch statement for frequency counting of each digit.
Aucun commentaire:
Enregistrer un commentaire