int main()
{
int position, innum, n, i, a[100];
cout << "Please input a number: ";
cin >> n;
cout << "\nPlease input the " << n << " numbers: \n";
for (i=0; i<n; i++)
cin >> a[i];
cout << "\nThe following are the list of numbers: \n";
for (i=0; i<n; i++)
cout << " " << a[i];
cout << "\n\nEnter number to be search: \n";
cin >> innum;
innum == a[i];//nevermind this much for im still in deep confusion as to how to go about this
cout << "Number " << innum << "is present at position " << innum;
system("pause>0");
return 0;
}
this should be the output:
input n: 8 (n) 8 is a variable
enter 8 numbers
100 53 84 320 3 12 43 121
enter number to be search: 320
number 320 is present at position 4
number 320 is present at position 8
#include <iostream>
usingnamespace std;
int main()
{
int position, innum, n, i, a[100];
cout << "Please input a number: ";
cin >> n;
cout << "\nPlease input the " << n << " numbers: \n";
for (i=0; i<n; i++)
cin >> a[i];
cout << "\nThe following are the list of numbers: \n";
for (i=0; i<n; i++)
cout << " " << a[i];
cout << "\n\nEnter number to be search: \n";
cin >> innum;
innum == a[i];//nevermind this much for im still in deep confusion as to how to go about this
cout << "Number " << innum << "is present at position " << innum;
system("pause>0");
return 0;
}
innum == a[i];//nevermind this much for im still in deep confusion as to how to go about this
Just loop over the a[] array and over each iteration test if a[i] == innum.
If it is == then cout << "Number " << innum << "is present at position " << i;
You should also always (if possible) have 'for' loops like this: for (int i=0; i<n; i++) //declare 'int i' in the loop itself to keep things local