+ 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; }
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.
+ 4
ok thanks
+ 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;
}
+ 3
https://code.sololearn.com/c64kVeQ60IUU/?ref=app
your problems is in loop