| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
test array
hi guys
i hope this one is legal this time ,howcan i test if the numbers in array are all equal ,, and also how can i know the first and the middin and the last number in array, |
|
#2
|
||||
|
||||
|
Try google'ing for simple tutorials about using Arrays in C++
This one is a decent start: http://cplus.about.com/od/beginnerc...l/aa050102a.htm |
|
#3
|
|||
|
|||
|
Code:
include <iostream>
using namespace std;
int main()
{
const int arraySize = 100;
int array[arraySize];
int size;
int middle;
cout << "How many elements will the array have? ";
cin >> size;
//Initialize all elements of the array to 0.
for(int cntr = 0; cntr < size; cntr++)
{
array[cntr] = 0;
}
cout << endl;
// Here you can ask the user if they want to input
// the array elements via cin >> in a for loop.
middle = (size/2) - 1;
cout << "First element: " << array[0] << endl;
cout << "Middle element: " << array[middle] << endl;
cout << "Last element: " << array[size - 1] << endl;
return 0;
}
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > test array |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|