0

C++, Competetive program It's hard for me to crack this problem Help me .

write a c++ program using iostream that asks a user to enter 10 integers in an array? It then asks for a number to search and prints all the locations where the number is present? Ans-> As i try to made the program but i am stuck my program taking input properly and when i ask user to search a specific number its also working fine but what if we have multiple number in same array how can we find the specific number in an array and print their index number respectively

29th Jun 2021, 4:29 AM
Nitin Bisht
Nitin Bisht - avatar
7 Réponses
+ 2
"What if we have multiple number in same array" Just remove the `break` statement in the for...loop you used to find indices of matching elements. The task didn't specificly tell you to print "Sorry you have enter wrong number" did it? cause unnecessary outputs may fail your attempt in such challenges. Outputs must *strictly* follows the instruction, no more and no less.
29th Jun 2021, 5:09 AM
Ipang
+ 2
No bro, no dumb, just forgot some things LOL Next time post your code bit link ok bro 👌
29th Jun 2021, 5:19 AM
Ipang
+ 2
Bro you can create new code in Playground, paste your code copied from your laptop IDE. And then you can save it, and share the link, just follow this easy steps 👍 https://www.sololearn.com/post/75089/?ref=app
29th Jun 2021, 5:28 AM
Ipang
+ 1
Ipang how dumb I am lol thanks again bro 😁
29th Jun 2021, 5:17 AM
Nitin Bisht
Nitin Bisht - avatar
+ 1
Ipang I don't know how to send code by link , either I write the whole code or I copy paste from laptop ide
29th Jun 2021, 5:26 AM
Nitin Bisht
Nitin Bisht - avatar
+ 1
Ipang got it .
29th Jun 2021, 5:30 AM
Nitin Bisht
Nitin Bisht - avatar
0
#include<iostream> using namespace std; int main(){ int array[10],i; //Asking from user to enter number cout<<"Enter 10 number to submit "<<endl; for( i=0;i<10;i++) { cin>>array[i]; } //printing the number user have submit cout<<"The number you have entered is"<<endl; for( i=0;i<10;i++){ cout<<array[i]<<endl; } //Asking for any random and return their index number int num; cout<<"Enter the number which you want to know their location"<<endl; cin>>num; for( i = 0; i < 10; i++){ if(array[i] == num){ cout << "Element found at index " << i; break; } } for(i=0;i<10;i++){ if(array[i] != num){ cout<<"Sorry you have enter wrong number"<<endl; break; } } return 0; }
29th Jun 2021, 4:47 AM
Nitin Bisht
Nitin Bisht - avatar