Home > Back-end >  Input the number ten, with the first number will be the biggest
Input the number ten, with the first number will be the biggest

Time:12-18

Can you help me have a look at where is wrong,,
//input 10 integers, one of the largest number with the number 1
#include
using namespace std;
Int main ()
{
Void fun (int *);
Int a [10], * p, I;
P=a;
for(i=0; i<10; I++)
Cin> A, [I].
Fun (a);
for(i=0; i<10; I++)
Coutreturn 0;
}
Void fun (int * p)
{
Int I, j, t, k=0;
For (I=k; i<9. I++)
{

for(j=i+1; J<10; J++)
{
If (* (p + I) & lt; * (p + j))
{
K=j;
break;
}
}
}
T=* p;
* p=* (p + k);
* (p=t + k);
}

CodePudding user response:

You this is a little trouble, if simply exchange the biggest and the first words, you can consider this, I changed the fun function on the basis of you,
 # include 
using namespace std;

Void fun (int *);

Int main ()
{
Int a [10], I;
Cout & lt; <"Please input the number 10:" & lt; for (i=0; i <10; I++)
{
Cin & gt;> A, [I].
}
Fun (a);
Cout & lt; <"After the exchange:" & lt; for (i=0; i <10; I++)
{
Cout & lt; }
return 0;
}
Void fun (int * p)
{
int k=0;
For (int I=0; i <10; I++)
{
If (p [I] & gt; P [k])
{
K=I;
}
}
Int temp=p [0];
P=p [0] [k].
P=\ [k];
}

CodePudding user response:

sovereign treasure, 1/f, reference response:
you this is a little trouble, if simply exchange the biggest and the first words, you can consider this, I changed the fun function on the basis of you,
 # include 
using namespace std;

Void fun (int *);

Int main ()
{
Int a [10], I;
Cout & lt; <"Please input the number 10:" & lt; for (i=0; i <10; I++)
{
Cin & gt;> A, [I].
}
Fun (a);
Cout & lt; <"After the exchange:" & lt; for (i=0; i <10; I++)
{
Cout & lt;
}
return 0;
}
Void fun (int * p)
{
int k=0;
For (int I=0; i <10; I++)
{
If (p [I] & gt; P [k])
{
K=I;
}
}
Int temp=p [0];
P=p [0] [k].
P=\ [k];
}

Understand, is I think complex, thought is similar to selection sort, with two loops, so,

CodePudding user response:

#include
Int main ()
{
Int I, ram, a [10], postion.//declare
for(i=0; i<10; I++)//input
{the scanf (" % d ", & amp; A [I]); }
Ram=a, [0].
for(i=0; i<10; I++)
{if (ram
A (postion)=a, [0]. A [0]=ram;//exchange
for(i=0; i<10; I++)//output
{printf (" % d ", a [I]); }

}
  • Related