+ 4

What's the problem in this code ? It is not giving proper output ?

#include <iostream> #include <ctime> using namespace std; int main() { int arr[10],i,minimum; for(i=1;i<=10;i++) { cout<<"Enter an Integer"; cin>>arr[i]; } minimum=arr[0]; for(i=1;i<10;i++) { if(arr[0]<arr[i]) { minimum=arr[i]; } } cout<<"Minimum input="<<minimum; return 0; }

1st Jun 2018, 5:17 PM
Shehroz Irfan
Shehroz Irfan - avatar
4 odpowiedzi
+ 2
both of your for loops should start with 0 and be i < 10. when working with arrays the starting position is 0 and you have your loops starting at 1 so you are not filling or reading arr[0]. Also your if statement should be if(arr[i] < minimum) that way you are checking to see if each number is less the way you have it you are just going to get a number less than arr[0] but may not be the lowest.
1st Jun 2018, 5:26 PM
Mooaholic
Mooaholic - avatar
+ 4
ok thanks
1st Jun 2018, 5:37 PM
Shehroz Irfan
Shehroz Irfan - avatar
+ 4
{}//What's the problem in this code ? It is not giving proper output ? #include <iostream> #include <ctime> using namespace std; int main() { int arr[10],i,minimum; for(i=0;i<10;i++) { cout<<"Enter an Integer"<<endl; cin>>arr[i]; } minimum=arr[0]; for(i=0;i<10;i++) { if(arr[i]<minimum) { minimum=arr[i]; } } cout<<"Minimum input="<<minimum<<endl; return 0; }
1st Jun 2018, 5:42 PM
Shehroz Irfan
Shehroz Irfan - avatar
1st Jun 2018, 5:24 PM
Arun Tomar
Arun Tomar - avatar