FAQ: Arrays: Lesson - Looping Through Arrays

This community-built FAQ covers the “Looping Through Arrays” exercise from the lesson “Arrays: Lesson”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn C

FAQs on the exercise Looping Through Arrays

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Guys can you help me to resolve the 2nd part of this problem?

Given the integer array arr2 , fill up the array so that each element in the array is four plus the index of the element.

Example:

arr[0] = 4 , arr[1] = 5 , arr[2] = 6 , etc.

That phrasing, “four plus the index” is important. How might you translate that to code?

1 Like

So far i get;

#include<stdio.h> int main() { int arr[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 22, 26, 28, 29}; int arr2[100]; int i = 0, aux = 1; // Code for Checkpoint 1 goes here for (i = 0; i < 20; i++){ printf("%d\n", arr[i]); } // Code for Checkpoint 2 goes here arr2[0] = 4; printf("%d\n", arr2[0]); for (i = 1; i < 100; i++){ arr2[i] = arr2[0] + aux; printf("%d\n", arr2[i]); aux++; } }
1 Like

Hi romanopaulo708735117,

i got to this awmser and i do think that should be right, anyway you should try.

#include<stdio.h>

int main() {
  int arr[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 22, 26, 28, 29};
  int arr2[100];
    for(int j = 0; j < 100; j++)
    {
      arr2[j] = j + 4; 
      printf("%i\n", arr2[j]);
    }
}

let me know if helped

So I’ve solve this 2nd problem task, and I can access the array elements using printf() but only using the negative indices, if I use positive indices, I keep getting 5, can anyone explain why this is the behavior?
image
This above is my soultion with the added printf() giving me just rows of 100 '5’s.

You have 100 “5” because you assigned 100 times “4+1”.
You should try to use the current index of the array and add 1 to it.

1 Like