Hi, I'm new to this so not sure if I'm posting this in the right place. I'm in my first semester of college and I'm taking an IT elective: Software Design. It doesn't involve any special programming language, it's simple, basic object-oriented design class. We were just introduced to the usage of ARRAYS, and recieved a few practice problems to work on.

I did one of them, so if anyone could please look it over to see if I'm on the right track and then I have a few on which similar examples may be helpful to follow.

PROBLEM #1:
You have already created an array named NUMBERS with 20cells. You are to initialize all of the cells with odd subscripts to 1 and all of the cells with even subscripts to 2.

MY TAKE ON IT:
I <-- 1
DOWHILE I<= 20
NUMBERS (I) <-- 1
I <--- I + 1
NUMBERS (I) <--- 2
I <--- I+ 1
ENNDO
PROBLEM #2:
You are to read 10 numbers from a data file into an array named List. Create another 10 element array named Reverse that is to contain the same items as List but in reverse order. For example, the first element in List will be placed in the last position of Reverse, the second element in List will be placed in the second-to-last position in Reverse, etc. After Reverse has been created, output the contents of both arrays.
EXAMPLE GIVEN in class notes:
I<--10
DOWHILE I>= 1
Write Numbers (1)
I<-- I -1
ENDDO

PROBLEM #3
You have created three arrays:
array A of size 100
array B of size 50
array C of size 200
You are to store the first 100 numbers (1,2,3,...,100) into array A, the first 50 positive odd numbers (1,3,5,...,) into array B, and the reciprocal of each position [C(5) = 1/5] into array C. Then, output each array.


I'm guessing where I'm stuck is how to deal with multiple arrays because of the quick examples I was given in class deal with only one array each time. So if anyone could please help me with this ARRAY concept, it would be very helpful because the semester is coming to an end and I can't afford to not understand this. Any help will be appreciated it, I have a bunch of other practice problems but not very relevant examples to follow. By the way this isn't for any grade, it's for my own practice before the final so please don't assume I'm trying to get answers without doing any work. I really dont understand the concept, and am only seeking help to be able to do the practice problems to prepare for the final exam. Thank you in advance.

PROBLEM #1:
You have already created an array named NUMBERS with 20cells. You are to initialize all of the cells with odd subscripts to 1 and all of the cells with even subscripts to 2.
MY TAKE ON IT:
I <-- 1
DOWHILE I<= 20
NUMBERS (I) <-- 1
I <--- I + 1
NUMBERS (I) <--- 2
I <--- I+ 1
ENNDO

Solution to problem 1:

public int[] NUMBERS = new int[20];
for (int i = 0; i<20; i+2) {
[INDENT]NUMBERS[i] = 2;[/INDENT]
}

for (int i = 1; i<20; i+2) {
[INDENT]NUMBERS[i] = 1;[/INDENT]
}

I do not know how to do problem number two with reading info from a file.

PROBLEM #3
You have created three arrays:
array A of size 100
array B of size 50
array C of size 200
You are to store the first 100 numbers (1,2,3,...,100) into array A, the first 50 positive odd numbers (1,3,5,...,) into array B, and the reciprocal of each position [C(5) = 1/5] into array C. Then, output each array.

I believe the following code will solve the above problem. HOWEVER I do not know what the output format of array C is supposed to be and it is going to be a nice big decimal with the code i am giving you.

public int[] A = new int[100];
public int[] B = new int[50];
public int[] C = new int[200];

for (int i = 0, j = 1; j<=100; i++, j+2) {
[INDENT]A[i] = j;[/INDENT]
}

for (int i = 0, j=1; i<50; j++, i++) {
[INDENT]B[i] = j;[/INDENT]
}

for (int i = 0; i<200; i++) {
[INDENT]
if (i==0) C[i]=0;
else {
[INDENT]
C[i] = 1/i;
[/INDENT]
}
[/INDENT]
}

thank you for working those problems out, but that's more complicated than what we do in class. I mean it seems like you are using a program language (we haven't learned any language yet, just covering the concepts in basic programming). sorry but in these 13weeks of this class, I haven't worked with any program like that you have written, it's been much more simple than that (introduction to programming). so know the basic way to work this problem?

hmm okay. to be honest, im not sure how to translate my code into what you are looking for. have you done loops yet? such as for loops...? and the language above is java.

TJ

answer for number 1 :)

#include<stdio.h>
#include<conio.h>

main()
{
      int NUMBERS[20], x;

      for(x=0; x<=20; x++)
      {
               //printf("Enter number %d: \n",x);
               //scanf("%d", &NUMBERS[x]);

               if (x%2==0)
               {
                                  printf("Enter number %d: 2 \n",x, NUMBERS[x]);
                                  }
               else
               {
                   printf("Enter number %d: 1 \n",x, NUMBERS[x]);
                   }
                   getch();
                   }
                   }

My version of problem 1:
N <-- 1
DOWHILE N <= 20NUMBERS (N) <-- (2 - (N modulus 2))
N <--- N + 1ENNDO

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.