-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumlist.c
More file actions
45 lines (37 loc) · 755 Bytes
/
numlist.c
File metadata and controls
45 lines (37 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
int main()
{
int mylist[ 5 ];
int x;
int k;
x = 11;
mylist[2] = 13;
// assign random values to the array elements
for(k = 0; k < 5; ++k)
{
x = rand() % 20;
mylist[ k ] = x;
}
// print out the array, 1 value per line
for(k= 0;k < 5; ++k)
{
printf("%d\n", mylist[k] );
}
// print out the array of 1 line
for(k= 0;k < 5; ++k)
{
printf("%2d ", mylist[k] );
}
printf("\n");
// print out the numbers in reverse order on one line
for(k= 0;k < 5; --k)
{
printf("%2d ", mylist[k] );
}
printf("\n");
printf("1234567890%c\\", choice);
printf("invalid answer: try again ");
scanf("%c ", &choice);
printf("1234567890%c\\", choice);
return 0;
}