main()
{
int a[22];
int index;
a[0] = 0;
a[1] = 1;
printf("a[ 0] = %5d
", a[0]);
printf("a[ 1] = %10d
", a[1]);
for (index=2; index < 22; index++)
{
printf("a[%2d] = ", index);
a[index] = a[index -1] + a[index-2];
printf("%5d ", a[index]);
printf("%5d ", a[index]- a[index-1]);
printf("%f
", (float) a[index] / (float) a[index-1]);
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
: to this source because I don't now how
: main()
: {
: int a[22];
: int index;
: a[0] = 0;
: a[1] = 1;
: printf("a[ 0] = %5d
", a[0]);
: printf("a[ 1] = %10d
", a[1]);
: for (index=2; index < 22; index++)
: {
: printf("a[%2d] = ", index);
: a[index] = a[index -1] + a[index-2];
: printf("%5d ", a[index]);
: printf("%5d ", a[index]- a[index-1]);
: printf("%f
", (float) a[index] / (float) a[index-1]);
: }
: }
explain?
Here's the rough syntax for a for construct:
for (initialization;condition;update)
{
code_to_execute_while_loop_is_operating;
}
The code_to_execute_while_loop_is_operating is any sequence of statements to be executed repeatedly. The loop is executed provided the boolean test condition is true.
Here's the sequence of events.
1) Upon reaching the 'for' loop, the initialization expression is evaluated (usually a counter is initialized).
2) The condition is tested. If the condition fails, control passes to the statement beyond the end of the for loop. If the condition passes, the loop code is executed, and then step 3 happens.
3) Control jumps back up to the update expression(usually a counter is incremented or decremented or updated in some fashion). Control immediately jumps to step 2) just previous.
Examine the for loop you do have, and see how it fits into this model. You should then be able to add another for loop after it by following the example. Or add another for loop inside the existing for loop if that's what you wanted. I'm thinking the former.