-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray2.c
More file actions
33 lines (24 loc) · 856 Bytes
/
array2.c
File metadata and controls
33 lines (24 loc) · 856 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
#include <stdio.h>
int main(void)
{
// ask for and get an int from the user
int array_size;
printf("Enter an array size: ");
scanf("%d", &array_size);
// declare an array of ints of array_size
int x_array[array_size];
//int *x_array = malloc(sizeof(int) * array_size);
// initialize each element in the array to i * 2
for (int i = 0; i < array_size; i++)
{
x_array[i] = i * 2;
}
// print out each element of the array and its index number
for (int i = 0; i < array_size; i++)
{
printf("%d: %d\n", i, x_array[i]);
}
//int calculated_size = sizeof(x_array)/sizeof(int);
//printf("The size of this array is: %d\nThe block of memory is %ld bytes.\nThe size of each int/element is %ld bytes.\n", calculated_size, sizeof(x_array), sizeof(int));
return 0;
}