Write a program that propmpts the user to input integer N. C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Write a program that propmpts the user to input integer N. C++

Then accept N integers and store them in one-dimensional array. Please note, that each integer is in the range [1,N-1]. Your task is to write a function which returns the number that appears twice in the array. It's guaranteed that there is only one pair of numbers with the same value (You may use dynamic arrays, functions and pointers) Example 1 Input 5 1 3 4 2 2 Output 2 Example 2 Input 3 1 1 2 Output 1

4th Dec 2020, 9:48 AM
Developer #1
Developer #1 - avatar
5 Answers
0
//here is the code #include<iostream> using namespace std; // void findPairNumber(int arr[],int n){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(arr[i] == arr[j] && i != j){ cout << arr[j]; return; } } } } // int main(){ int n; cin >> n; int arr[n]; for(int i=0;i<n;i++){ cin >> arr[i]; } findPairNumber(arr,n); return 0; }
4th Dec 2020, 11:11 AM
Developer #1
Developer #1 - avatar
+ 8
Developer #1 Kindly don't post the question of you are already aware of the answer! And I can see that you are saying that "can anyone check" Why don't you try it in code playground!! That will work ;)
4th Dec 2020, 1:17 PM
Piyush
Piyush - avatar
+ 1
Martin Taylor I know, but I want to check it. Is it right or not? Såñtösh Now you can see. I sent code
4th Dec 2020, 11:12 AM
Developer #1
Developer #1 - avatar
0
4th Dec 2020, 9:48 AM
Developer #1
Developer #1 - avatar
0
First show your code here
4th Dec 2020, 10:33 AM
Sâñtôsh
Sâñtôsh - avatar