|
-
October 2nd, 2010, 02:50 AM
#1
Need Help With The Array
hello guys can u tell me how i will solve this question with array
i answer it but i guess there is alot of problems and it doesnt work ,
THE QUESTION IS
==============
Write a function named insertzeros that takes as parameters : an array of integers , number of elements in the array which is passed by reference , a position in the array pos , an integer NB ( the number of zeros to be inserted ) , and a constant array SIZE ( maximum size ) . The function should insert NB zeros starting from pos.
the function prototype is :
void insertzeros ( int arr [], int & length , int pos , int NB , const int SIZE );
==============
PHP Code:
# include <iostream> using namespace std; void insertzeros( int arr [],int & length ,int pos , int NB, const int SIZE) { int i; for(int j=0; j<NB; j++) for ( i=length-1; i>pos; i--) arr [i+1]=arr[i]; length ++; for(int k=pos; k<NB; k++) arr [k]=0; int main () { int NB,pos,arr; cout << " Enter The Number Of Zeros " <<endl; cin >>NB; cout << " Enter The Position " <<endl; cin >>pos; cout << " Enter The Array Size "<<endl; for (int s=o; s<length+1; s++) cin>>arr[];
}
Last edited by jacksparrow; October 2nd, 2010 at 08:01 AM.
-
October 2nd, 2010, 03:34 AM
#2
Re: Need Help With The Array
[ Moved thread ]
// Please use CODE tags to make code more readable.
-
October 2nd, 2010, 04:08 AM
#3
Re: Need Help With The Array
ok sorry boss
next time am gonna use it
-
October 2nd, 2010, 07:23 AM
#4
Re: Need Help With The Array
 Originally Posted by jacksparrow
ok sorry boss
next time am gonna use it
You can edit the previous post as well.
-
October 2nd, 2010, 08:02 AM
#5
Re: Need Help With The Array
i edit the code ,,, why no one try to help me out in the answer... i thought it gonna be easy for the professionals
-
October 2nd, 2010, 08:22 AM
#6
Re: Need Help With The Array
 Originally Posted by jacksparrow
i edit the code ,,, why no one try to help me out in the answer... i thought it gonna be easy for the professionals
Now go back and use proper indentation and line up the braces. Once you do that, your biggest initial problem should be obvious.
Also, to get help, you need to be more specific than just saying it doesn't work. If there are compiler errors list them and tell us what line of code they're on.
-
October 2nd, 2010, 08:25 AM
#7
Re: Need Help With The Array
 Originally Posted by jacksparrow
i edit the code ,,, why no one try to help me out in the answer... i thought it gonna be easy for the professionals
Nothing is easy, don't ever take things for granted.
Next, properly indent the code as it still is a bit messy to read.
Third, when you compile this code, what's the first error message you see?
Fourth and the biggest mystery is, where is your array??
-
October 3rd, 2010, 08:03 AM
#8
Re: Need Help With The Array
 Originally Posted by potatoCode
Nothing is easy, don't ever take things for granted.
Next, properly indent the code as it still is a bit messy to read.
Third, when you compile this code, what's the first error message you see?
Fourth and the biggest mystery is, where is your array??
hello mate,, whats uP ?
ok lets to about the array
i should put it after using namespace right
# include <iostream>
using namespace std;
int arr = 10;
void insertzeros( int arr [],int & length ,int pos , int NB, const int SIZE)
-
October 3rd, 2010, 08:37 AM
#9
Re: Need Help With The Array
That's a single int. There's no array.
There is a function parameter specified to be an array with the same name, but it's an unrelated variable.
-
October 4th, 2010, 05:59 PM
#10
Re: Need Help With The Array
That is a very strange assignment. What is length vs. SIZE? Does he want you to grow the array? What if the number of zeroes to insert plus the starting position puts you beyond the length or max size? I'd guess that length is the current amount of data that has been assigned and that SIZE is the actual size of the array, arr. Is that correct?
-
October 5th, 2010, 07:10 AM
#11
Re: Need Help With The Array
yeah it's really missed up assignment i have been given from my doctor , and i still couldnt answer it well.. anyway ur right he want me to put zeros in the start of pos and if there is no space in the length i have to make space and put zeros
-
October 6th, 2010, 02:07 PM
#12
Re: Need Help With The Array
i edited now the function and i think its correct , all i need to do now cout and cin
PHP Code:
void insertzeros (int arr[],int &length,int pos,int NB,const int SIZE) { if (length==SIZE) { cout<<"Sorry array is fall"<<endl; return; }
for(int j=0;j<NB;j++) {
for (int i=length;i>=pos;i--) { arr[i]=arr[i-1]; } arr[i]=0; length++; }
-
October 6th, 2010, 02:40 PM
#13
Re: Need Help With The Array
 Originally Posted by jacksparrow
i edited now the function and i think its correct , all i need to do now cout and cin
PHP Code:
void insertzeros (int arr[],int &length,int pos,int NB,const int SIZE)
{
if (length==SIZE)
{
cout<<"Sorry array is fall"<<endl;
return;
}
for(int j=0;j<NB;j++)
{
for (int i=length;i>=pos;i--)
{
arr[i]=arr[i-1];
}
arr[i]=0;
length++;
}
Okaaaaaay. 
Well good luck with your program. I'm not sure what you are asking for at this point.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|