Hi, my father has been there for some aviation business and he liked it.Also welcome to the forum!
Ok so you have your array.If i understood the task, you should print out in the screen this numbers (output).
Are you aware of printf function? Also are you aware of the newline character?
Example
Code:
int a = 5;
int b = 10;
int c = 90;
printf("%d %d %d",a,b,c);
This will output
Now i will use the newline character \n to get 90 in a new line.
Code:
int a = 5;
int b = 10;
int c = 90;
printf("%d %d \n %d",a,b,c);
Output:
Ok now about the array.If i want to access the first element of the array i have to write it like this
If i want to access the i-th element of the array I write this
So how to print the 4th element of the array?
With this code
Code:
printf("%d",array[3]);
So how to print the i-th element of the array?
With this code
Code:
printf("%d",array[i]);
Ok, how to print all the elements of the array?
Code:
#include <stdio.h>
int main(void)
{
int array[] = {0,1,2,3,4,5,6,7,8,9};
int i;
/* Traverse trough the array */
for(i = 0 ; i < 10 ; i++)
{
/* Print the current element and leave a space */
printf("%d " , array[i]);
}
/* Just leave a line */
printf("\n");
return 0;
}
Output
Code:
Macintosh-c8bcc88e5669-9:~ usi$ ./px
0 1 2 3 4 5 6 7 8 9
Macintosh-c8bcc88e5669-9:~ usi$
Now , every two elements i print i will change line.An easy way of doing this is to have an extra variable named counter.I will increment by one in every loop iteration and when the counter is equal to two, then i will print a newline (change line) and then I will reset the counter to zero.
Code:
#include <stdio.h>
int main(void)
{
int array[] = {0,1,2,3,4,5,6,7,8,9};
int i,counter;
/* Traverse trough the array */
counter = 0;
for(i = 0 ; i < 10 ; i++)
{
/* Print the current element and leave a space */
printf("%d " , array[i]);
counter++;
if(counter == 2)
{
printf("\n");
counter = 0;
}
}
/* Just leave a line */
printf("\n");
return 0;
}
Output:
Code:
Macintosh-c8bcc88e5669-9:~ usi$ ./px
0 1
2 3
4 5
6 7
8 9
Macintosh-c8bcc88e5669-9:~ usi$
Now try to apply these on your homework...Or get inspired by this and find a way of achieving the results you want.
If trouble comes up, post back
Hope this helps.