29 lines
895 B
C
29 lines
895 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main(int argc, const char *argv[])
|
|
{
|
|
// You declare a array by simply putting [<amount>] behind your variable.
|
|
int Numbers[5];
|
|
|
|
// In c the first element in the array has the index 0.
|
|
// So to access the last one you have to subtract one from the element count.
|
|
// TODO: use the []-operator to fill out the rest of the array with the numbers 1 - 5
|
|
Numbers[0] = 1;
|
|
|
|
// TODO: now use the Numbers from the array and square them. After that write them back into the array.
|
|
|
|
// If you want to calculate the element count of a array
|
|
// you can use this line of code:
|
|
int count = sizeof(Numbers)/sizeof(Numbers[0]);
|
|
// Printing the array
|
|
for(int i = 0; i < count; i++)
|
|
{
|
|
printf("%d ", Numbers[i]);
|
|
}
|
|
|
|
// you can also have multidimensional arrays.
|
|
// you simply add more []
|
|
// Example: int 3D_Matrix[10][10][10];
|
|
}
|