This what I'm suppoesed to be doing. Allocate enough memory to hold 50 integers using malloc and assign the pointer returned by malloc to "ia". Using only "ip" populate the array with fifty random integers. Using only "ip" display the contents of the array both forward and backard. The function randnum was given. I'm not getting 50 random integers. Could someone tell me the problem area(s) where I should be looking at?
Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int randnum(int range); int main () { int *ia, *ip; srand(time(NULL)); ia = malloc (50 * sizeof(int)); if (ia == NULL) { printf("Cannot malloc\n"); exit(1); } for (ip = ia; ip < ia + 50; ip++) *ip=randnum(50); printf("%-3d", *ip); return 0; } int randnum(int range) { int v; v = rand(); return (v * range / (RAND_MAX + 1)); }