Jan 26, 2012 at 8:10am UTC
int x=0;
int array[5];
int arr[5];
cout<<"enter 5 numbers"<<endl;
for(int i =0; i<5; i++)
{
cin>>arr[i];
}
for(int j=0; j<5;j++)
{
for(int k=j+1; k<5; k++)
{
if(arr[j]<arr[k])
x=arr[j];
else
x=arr[k];
in this code i want in every time looping the X value dont return to 0 for example : when arr[0]<arr[1] then x= arr[0] and next loop , it compares the new value of array with X which is = arr[0]
sorry i know my explanation is terrible :/
Jan 26, 2012 at 11:49am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
int x = 0;
int array[5];
int arr[5];
cout<<"enter 5 numbers" <<endl;
for (int i = 0; i < 5; i++)
{
cin >> arr[i];
}
for (int j = 0; j < 5;j++)
{
for (int k = j + 1; k < 5; k++)
{
if (arr[j] < arr[k])
{
x = arr[j];
}
else
{
x = arr[k];
}
}
}
You could at least make you code readable.
Your code was terrible.
And then, I really dont understand exactly what is it that you want to do?
Are you trying to find the biggest/smallest?
Last edited on Jan 26, 2012 at 11:50am UTC