Given a number N and an array A of N numbers. Print the lowest number and its position.
#include <iostream>
using namespace std;
int main() {
int n,i,pos=0;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int low = arr[0];
for(i=0;i<n-1;i++){
if(arr[i+1] < low){
low = arr[i+1];
pos = i+1;
}
}
cout << low << " " << pos+1;
return 0;
}
Comments
Post a Comment