R
RadiationX
Hello, I have a simple print output questioin. What I'm trying to do is
print an array of lenth 20 which holds 20 ints in the form of five
columns and four rows. like this below
12 80 90 6 7
1 6 99 8 9
8 3 5 3 12
9 4 2 2 15
I have no idea how to print it like this. Below is what I have so far.
It's wrong but I think I'm on the right track. What the code below does
is print one column broken up into five parts. I really would
appreciate some help.
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
int random();
int main()
{
int j;
int user;
int k;
int golf[20]= {0};
int b;
srand(time(NULL));
// printf("%s%13s\n", "Element", "Value" );
for ( k = 0; k< 20; k++ )
{
b = random();
golf[20] = b;
if(k%4==0)
{
printf("\n");
}
printf("%8d\n", golf[20]);
}
system("PAUSE");
return 0;
}
int random()
{
int x;
x = 1 + rand()%99;
return x;
}
print an array of lenth 20 which holds 20 ints in the form of five
columns and four rows. like this below
12 80 90 6 7
1 6 99 8 9
8 3 5 3 12
9 4 2 2 15
I have no idea how to print it like this. Below is what I have so far.
It's wrong but I think I'm on the right track. What the code below does
is print one column broken up into five parts. I really would
appreciate some help.
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
int random();
int main()
{
int j;
int user;
int k;
int golf[20]= {0};
int b;
srand(time(NULL));
// printf("%s%13s\n", "Element", "Value" );
for ( k = 0; k< 20; k++ )
{
b = random();
golf[20] = b;
if(k%4==0)
{
printf("\n");
}
printf("%8d\n", golf[20]);
}
system("PAUSE");
return 0;
}
int random()
{
int x;
x = 1 + rand()%99;
return x;
}