i want to print 1000 random numbers saved in a array. Numbers have to be between 1 and 10000.
I put srand(time(NULL)) in my main Function and the array have to be filled with random numbers in my init function. The ausgabe function is for formated output.
But rand fills my array with numbers all in row.
I hope you can help me.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ARR_SIZE 1000
void init(int * ptr, int size){
for (int i = 0; i < size; i++){
*(ptr + i) = (rand() %10000+1);
}
}
void ausgabe(int * ptr, int size){
for (int i = 0; i < size; i++){
printf("%5i\t", * ptr + i);
if ((i + 1) %10 == 0){
printf("\n");
}
}
printf("\n\n");
}
int main(){
int zufall[ARR_SIZE];
srand(time(NULL));
init(zufall, ARR_SIZE);
printf("\n\t\t\t---unsortierte Ausgabe---\n\n");
ausgabe(zufall, ARR_SIZE);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire