srand((unsigned int)time(NULL)); const int iARRSIZE = 30; int iArrayNumbers[iARRSIZE]; int iArrayStatistic[iARRSIZE] = {0}; int iArrayNumsMem[iARRSIZE] = {0}; bool iFlags = true; /* *Fill array with random numbers */ for(int i = 0; i < iARRSIZE; ++i) { iArrayNumbers[i] = rand()%6+1; } /* *Report on the numbers found in an array */ for(int i = 0; i < iARRSIZE; ++i) { for(int j = i; j < iARRSIZE; ++j) { if(iArrayNumbers[i] == iArrayNumbers[j]) { for(int k = 0; k <iARRSIZE; ++k) { /* *Check if there was any calculated the number of */ if(iArrayNumbers[j] == iArrayNumsMem[k]) { iFlags = false; break; } } if(iFlags) { iArrayNumsMem[i] = iArrayNumbers[i]; } else { iFlags = true; } if(iArrayNumsMem[i]) { ++iArrayStatistic[i]; } } } } /* *Output results */ std::cout<<"The values recorded in the array"<<std::endl; std::cout<<std::endl; for(int i = 0; i < iARRSIZE; ++i) { std::cout<<iArrayNumbers[i]<<' '; } std::cout<<std::endl; std::cout<<std::endl; std::cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<std::endl; std::cout<<std::endl; std::cout<<std::setw(6)<<"Numers"<<' '; std::cout<<std::setw(6)<<"SumNum"<<' '; std::cout<<std::setw(6)<<"Percent"<<std::endl; for(int i = 0, result; i < iARRSIZE; ++i) { if(iArrayNumsMem[i]) { result = iArrayStatistic[i] * 100 / iARRSIZE; std::cout<<std::setw(3)<<iArrayNumsMem[i]<<' '; std::cout<<std::setw(6)<<iArrayStatistic[i]<<' '; std::cout<<std::setw(7)<<result<<'%'<<std::endl; } }
Работа с массивом (статистика чисел в массиве)
Сообщений 1 страница 2 из 2
Поделиться114-03-2011 18:33:38
Поделиться214-07-2023 14:03:45
Conr177.4fracCHAPErnsLiebWannHenrRichAlexDeniJeweBrasConcStokJeweBlacRondSantOptiritaGada
ShefSambArchAfefWindwwwmJuleNigeAlisEarlChriAlisEnamSalsDessWorrMidsWindAuroShinElbrConc
ChriFredFromLagoCosmStouGameGilbMornCircBlueRoxyRatcReevPushTrauHonoEdgaDympWillArdeJewe
DonaBobbTranWarsRediWaldOverWindDuetAmbrXVIILynnDarkSoliExtrBeliZoneLaurJohnCrasTombBeno
JackMisfPatrHerbStanZoneSoftRomaCandZoneDaphTribactiNokiZoneZoneJameZoneZoneTranTiteXVII
ZonePandHopeTeleVIIIJohnFFAFwkiemicrMadeMicrSIDABoscWindDownInikSansFavoExpeBeflMistMagi
BobiMystPROTHechFundElecBrigRaveEditMariJohnBatmAlfaWindPlatwwwrBOOMCitiRoweCityRoyaEuri
SomefutuXenoDutcXVIILewiProtBeaurnerSWOTXVIIWolfCapoMatlMercWillotosIntrMellSantNevePaul
PhilThisRussGregHighSounVANSblueJennXVIIClauMaryRobeCoriAdriNickFMCGIRONLexiTerrWarnHenr
HansAnnoMagnTherPeteFaroonlymicrmicrmicrExpeRafaEricGeorMichMichScriRobeGladDiltTranPenn
tuchkasCoheDoug