English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Okay, so here's the link for the problem http://www.pic.ucla.edu/~nathan/cgi-bin/moin.cgi/la1
I'm having trouble on the first part.
For the first function

intialize_array: I'm confused on how I can get the print_array function to print out NA's.. If I just initialize all values in the array to a default value such as -1, then ask the print_array function to print out the values, the values will read 'NA'?

for example:
(initialize_array(int a[],int n1) {
for (int i =0; i < a[n1]; i++)
a[i] = -1;
a[n1] = n1;


Also, for the copy_array function.. i wasn't sure if i was approaching this right

copy_array(int a[], int n1, int b[], int n2);
for(int i =0; i < n1+1; i++)
b[i] = a[i];
b[n2] = n2;

thanks so much

2007-01-28 12:55:40 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

thanks for your help, the n2 represents, the new position prompted from the user.. so a is the old pointer, b is the new pointer, n1 is the old position.,.
and i'm trying to create a new array with the old values, and then add the integer for the last value in the new array.. (as it shows in the output in the link)

2007-01-28 14:14:04 · update #1

2 answers

For the first part, initialize your array to -1 and then put an if in your print statement so that it prints "NA" if the number is negative. Something like:

for(i=0; i {
if( array[i] < 0)
printf("%d: NA\n", i);
else
printf("%d; %d\n", i, array[i]);
}

Or use cout> statements similarly.

For the copy function, I think you're going to need to use pointers. I can't really tell if your approach is right otherwise because I'm not sure what the purpose of n2 is.

2007-01-28 13:09:20 · answer #1 · answered by sdc_99 5 · 0 0

i'm 15 so right here its is going. i'm a newbie. first create a for loop which will deposit the numbers like for (int i =0; i < a[n1];){ cout << "enter A num:"; cin >> array[i]; // I did a array[ i] because the for loop will attempt each and every of the conceivable nums it will be decrease than a[n1] so if it start up from a million then the first num be tale in arry[a million] cout << "WANNA enter yet another NUM[Y/N]"; cin >> extra; // create a char noted as cin so u can desposit extra num if the person needs. if(extra == 'n') smash; }else{ i++; } then later if u want to keep in mind the array decrease back use this loop for (int i =0; i < a[n1];){ cout << "array" << i << " is " << array[i] << endl; // will say Array a million = and so on etc. } wish THIS facilitates. ~~help ME~~ i'm 15 and that i'm gaining knowledge of programming. I actually have a 4.0 GPA yet i imagine I received't get larger than seven hundred on the SAT so How do i'm stepping right into a strong college.

2016-12-03 04:17:16 · answer #2 · answered by ? 3 · 0 0

fedest.com, questions and answers