Hello, I\'m not sure why this doesn\'t work. I want a list of 16 random numbers
ID: 3621457 • Letter: H
Question
Hello, I'm not sure why this doesn't work.I want a list of 16 random numbers at first, and then I want another list four times the length of the first list, and so on. The last list will be 4096 random numbers long.
Here is the code:
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i;
int j=16;
srand (time(NULL));
i = (float)rand()/(RAND_MAX+1);
for(j=16; j<4096; j*=4)
{
printf("This is the start of the size %d vector ", j);
{
for(i=0; i<j; i++)
{
printf("%.3lf ", (float)rand()/(RAND_MAX+1));
}
}
printf(" ");
printf(" ");
}
getche();
return(0);
}
Thanks for your help
Explanation / Answer
please rate - thanks
It works fine.
all I did is change the formatting a bit
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i;
int j=16;
srand (time(NULL));
i = (float)rand()/(RAND_MAX+1);
for(j=16; j<4096; j*=4)
{
printf("This is the start of the size %d vector ", j);
{
for(i=0; i<j; i++)
{
printf("%.3lf ", (float)rand()/(RAND_MAX+1));
if((i+1)%10==0)
printf(" ");
}
}
printf(" ");
printf(" ");
}
getche();
return(0);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.