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
5 Réponses
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;
}
+ 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 ;)
+ 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
0
0
First show your code here