Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Help with For Statement names integer array with 20 elements. display the ele

ID: 3555621 • Letter: 1

Question

1. Help with For Statement names integer array with 20 elements. display the elements in the array

2. Question / Request : Look at Example, Look at my Code... did I accomplish the task.

My Code:

Declare integer names[20]
Declare integer index = 0

Declare integer counter = 1

For counter = 1 to 20
        Display names[counter]

         counter = counter + 1
        done
End For

Example:

In the example provided below. I need to understand the intent of the for statement below.

What does i Represent below I Step 2: is this suppose to be the counter

is Step 3 declaring a starting value for i


Step 1. Declare names as the Integerarray of size 20.
Step 2. Declare i as integer
Ste 3. Set i = 1

Step 4.
LOOP: for i = 1to 20 incrementby 1
do
Display names[i]
done
End LOOP
End Program

Explanation / Answer

yes i is counter step 3 is initializing the counter although you can initialize it in the for loop itself like

for(int i=1;i<20;i++)

{

//your code

}

however this will also work but you can skip step 3 and do it like below

int i;

for(i=1;i<20;i++)

{

// you code

}

your code

Step 1. Declare names as the Integerarray of size 20.
Step 2. Declare i as integer
Step 3.
LOOP: for i = 1to 20 incrementby 1
do
Display names[i]
done
End LOOP
End Program

#include<stdio.h>

#include<stdlib.h>

int main()

{

int names[ ]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};

int i;

for(i=1;i<20;i++)

{

printf("%d ",names[i]);

}

system("pause");

}