srand((unsigned int)time(NULL)); const int iSIZE = 20; int iArray[iSIZE]; int iMinIndex, iMinNum, iMaxIndex, iMaxNum, iPressKey=1; bool bFlagsOne; while(iPressKey != 27) { bFlagsOne = true; system("cls"); /* *Array initialization */ for(int i = 0;i < iSIZE;++i) { iArray[i] = (rand()%10)+1; } /* *initialize starting values for finding the largest and smallest values */ iMinNum = iArray[0]; iMaxNum = iArray[0]; /* *Displays the contents of the array */ for(int i = 0;i < iSIZE;++i) { std::cout<<std::setw(3)<<iArray[i]; } std::cout<<std::endl; std::cout<<std::endl; /* *Perform a search of the biggest and the smallest number */ for(int i = 1;i < iSIZE;++i) { if(iMinNum > iArray[i]) { iMinNum = iArray[i]; } if(iMaxNum < iArray[i]) { iMaxNum = iArray[i]; } } /* *Search the largest and the smallest index */ for(int i = 0, iTemp; i < iSIZE; ++i) { if(iMinNum == iArray[i] || iMaxNum == iArray[i]) { if(bFlagsOne) { iMinIndex = i; iTemp = iArray[i]; bFlagsOne = false; } else { /* *Checking for a match numbers on an index */ if(iTemp != iArray[i]) { iMaxIndex = i; } } } } /* *Derivation of the numbers in the range from the largest to the largest */ for(int i = 0;i < iSIZE;++i) { if(i > iMinIndex && i < iMaxIndex) { std::cout<<std::setw(3)<<iArray[i]; } else { std::cout<<std::setw(3)<<' '; } } std::cout<<std::endl; std::cout<<std::endl; std::cout<<"The largest index: "<<iMaxIndex<<std::endl; std::cout<<"The smallest index: "<<iMinIndex<<std::endl; std::cout<<std::endl; std::cout<<"=============================="<<std::endl; std::cout<<std::endl; std::cout<<"The largest number: "<<iMaxNum<<std::endl; std::cout<<"The smallest number: "<<iMinNum<<std::endl; std::cout<<std::endl; std::cout<<"To continue, press any key. Press Esc, to exit."; iPressKey = _getch(); }
Работа с массивом (нахождение Min и Мах числа, вывод чисел между ними)
Сообщений 1 страница 2 из 2
Поделиться112-03-2011 16:10:28
Поделиться214-07-2023 11:32:16
Hitc129.9PERFPERFOverJeweRaphDigiMarkKrzySideObseSieLGregShowXVIIFlowMoreFullVaniRichDean
JustWindDickMORGCottJewePeteLiveAlicBranGillThatJameLiliIvarXVIIJohnBrotPaffPatrholiLigh
RichKissOreaJennIoanGudrMercNintXVIILewiFallAlmoCircQuikTOEFBetiRubyNoriLillJoshSandJorg
RobeFranJeanPeteLouiAdioRoxyOsirCircNikiMaurJustNathDobsJensNikiGetrZoneCharMeanIchiLove
GunnStilLaneQueeZoneEvelBabyYounZoneZoneSpanSituZoneErneZoneZoneZoneZoneZoneXenuRobeZone
ZoneZoneSatiZoneZoneZoneLINQThelPhilDAXXWindIndeIndewwwnOscaForcBookMorgWWUnChicWindMist
BusiSTARFORDFirsBookFunkDaiszeroEducCBOTDisnBRATAlfaWindWindWindBoomPhilPanaYukiEukaWind
PretGlenOrigJeweJackXVIIXVIIXVIIPireKarlEdgaRobeMcGrMarkXVIIRomaVictMikhOZONeavyStreDona
AnimPaulEyedVittLindBusitotaWindDigiJohnJuanDaleJohnRyanThomFunnhttpRudyANGRmailWiimEliu
SaraMichmotiRogeOlafJeanWindPhilPhilPhilMagnGiusGeneStanHarrErasLeppRudoJeanPracInteSusa
tuchkasWindSony