Structure of the Problem Requirements
Array is a Data Structure which hold the record on different index. In this problem we learn how to know the index number of an array. The user will enter five digits and then after this enter a digit from these digits . As the reply the program will give output which is the index number of that specific number.
Source Code
using namespace std;
int main ()
{
int num [5];
int index=0;
for(int i=0;i<5;i++)
{
cout<< " Enter Your Number :";
cin>>num[i];
}
cout<<" Enter the Number to get it index number : ";
cin>>index;
for (int i =0;i<5;i++)
{
if(num[i]==index)
{
cout<<" \n \n Your Number Exist in Array Index :"<<i;
}
}
}
Output of the Program
Index Number |
Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.
That is the most contrived way of saying: "Write a search function" ever.
ReplyDeleteSearching is Killer Process :(
DeleteI find using cout inside loops like that teaches poor structure.
ReplyDeleteSure, it prints out for every entry but I think it would be better to store the result and exit the loop.
Also, indentation seems to have been lost. Probably down to the style sheet.