やあみんな、私はこれに3日間取り組んできましたが、私が見たすべてのものから何も思いつきませんでした.
とにかく配列を変更したり、新しい配列を作成したりせずに、約250個の浮動小数点数の配列を取り、K番目に大きい値を見つけようとしています。
他の関数ではデータを正しい順序で配置する必要があり、Arduino はメモリ空間にそれ以上の値を保持できないため、変更するか、新しいものを作成できます。
配列内の値は重複する可能性があります (おそらくそうなるでしょう)。
EG として : 配列がある場合 ::: 1,36,2,54,11,9,22,9,1,36,0,11; 最大から最小までは :: 1) 54 2) 36 3) 36 4) 22 5) 11 6) 11 7) 9 8) 9 9) 2 10) 1 11) 1 12) 0
どんな助けでも素晴らしいでしょう。私にとってこれをうまくやってくれる機能を求めるのは多すぎるかもしれません:)ハハハ
ここに私がこれまでに持っているコードがありますが、まだ重複を機能させようとさえしていません。何らかの理由で、何らかの理由で1つの答えしか得られません.2ですが、理由はわかりません
void setup()
{
Serial.begin(9600);
}
void loop ()
{
int Array[] = {1,2,3,4,5,6,7,8,9,10};
int Kth = 6; //// just for testing putting the value as a constant
int tr = 0; /// traking threw the array to find the MAX
for (int y=0;y<10;y++) //////////// finding the MAX first so I have somewhere to start
{
if (Array[y]>Array[tr])
{
tr = y;
}
}
Serial.print("The max number is ");
int F = Array[tr];
Serial.println(F); // Prints the MAX ,,, mostly just for error checking this is done
///////////////////////////////////////////////////////// got MAX
for ( int x = 1; x<Kth;x++) //// run the below Kth times and each time lowering the "Max" making the loop run Kth times
{
for(int P=0;P<10;P++) // run threw every element
{
if (Array[P]<F)
{
for(int r=0;r<10;r++) //and then test that element against every other element to make sure
//its is bigger then all the rest but small then MAX
{
Serial.println(r);
if(r=tr) /////////////////// done so the max dosent clash with the number being tested
{
r++;
Serial.println("Max's Placeing !!!!");
}
if(Array[P]>Array[r])
{
F=Array[P]; ////// if its bigger then all others and smaller then the MAx then make that the Max
Serial.print(F);
Serial.println(" on the ");
}
}}}}
Serial.println(F); /// ment to give me the Kth largest number
delay(1000);
}