| | |
Insert a number in an array
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2005
Posts: 15
Reputation:
Solved Threads: 0
im trying to insert a number into an array but when i insert a number it deletes the last number instead of increasing the array size by one....this is the code i have:
void Insertion(float T[100],int size)
{
float target = 0.0;
cout<<"Enter the number you are inserting"<<endl;
outData<<"Enter the number you are inserting"<<endl;
cin>>target;
int k=0;
while((k< size) && (T[k] < target))
k++;
for(int index = size -1; index>=k;index --)
{
T[index + 1] = T[index];
}
T[k] = target;
size = size + 1;
}
Thanks
void Insertion(float T[100],int size)
{
float target = 0.0;
cout<<"Enter the number you are inserting"<<endl;
outData<<"Enter the number you are inserting"<<endl;
cin>>target;
int k=0;
while((k< size) && (T[k] < target))
k++;
for(int index = size -1; index>=k;index --)
{
T[index + 1] = T[index];
}
T[k] = target;
size = size + 1;
}
Thanks
![]() |
Similar Threads
- Inserting a number to an array (C++)
- Bubble sorting and finding a location of a number in array (C++)
- appending and subtracting a number in an array (C++)
- Trying To Find The Square Root Of Each Number Of A Array (C++)
- help with inserting a number into an array (C++)
Other Threads in the C++ Forum
- Previous Thread: help with inserting a number into an array
- Next Thread: Colour & graphics in DOS
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





