| techboy (3) | |
|
hello everybody! I got a very big problem on inputting nd displaying the arrays. As Im new to programming specially to this topic..this is the question nd the code Write a program that populates an array of size 20 with random integer numbers between the ranges of 1 to 100 (inclusive). Then repeatedly asks the user to enter a number. For each number entered, display the position of that number in the array. If the number doesn’t exist, display a message indicating that the number is not found. If the number appears more than one time, in the array, display all the positions. The user should be asked to enter a sentinel value if no more search is needed. include<iostream> using namespace std ; const int no=20 ; int main() { int array[20]={12,22,56,45,78.96,63,74,55,77,99,88,33,22,11,44, 72,29,31,30} ; int i , val ; for ( i = 0; i<no ; i++ ) { cout << " please enter a value " << endl ; cin>> val ; for ( int i = 0 ; i<array[no-1] ; i++ ) { cout << i << endl ; } } return 0 ; } | |
|
|
|
| TheJJJunk (181) | |||||
rand and srandhttp://www.cplusplus.com/reference/clibrary/cstdlib/rand/
| |||||
|
|
|||||
| maeriden (244) | ||
Use code tags
This only prints the value of i for 20 times The above code won't print a message if the number is not in the array though | ||
|
Last edited on
|
||