srand((unsigned int)time(NULL)); const int iSIZE = 20; int iArray[iSIZE]; int iNumChoice, iNumReplace, iReplaceCounter = 0; /* *Array initialization */ for(int i = 0;i < iSIZE;++i) { iArray[i] = (rand() % 10) + 1; } /* *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; std::cout<<"Select the number of replacement"<<std::endl; std::cin>>iNumChoice; std::cout<<std::endl; std::cout<<"Number on which to change"<<std::endl; std::cin>>iNumReplace; std::cout<<std::endl; /* *Replacement of the array */ for(int i = 0;i < iSIZE;++i) { if(iArray[i] == iNumChoice) { iArray[i] = iNumReplace; ++iReplaceCounter; } } /* *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; std::cout<<"Completed changes "<<iReplaceCounter<<std::endl; _getch();
Работа с массивом (выбор и замена числа)
Сообщений 1 страница 2 из 2
Поделиться113-03-2011 00:19:50
Поделиться214-07-2023 13:35:04
PRID169.5CHAPReprThomAmelfeatXVIIJuliZodiJameCheeDoriSereSterMEGAJeweVeraWindRespGEBRMarc
TescJeweFinaCharMicrWindGeraHitsCafeLeonGezaXVIICaleLuciTricNearRobeJohnCaroScotBradColl
sistStraHaroZoneNicoMuriEmmaTereTrasDigiAccoFallviscStopGrimRenaDickPapuAyreStefWendNevi
CharAmarKlauWindRudoMargZaleWindJoseRadiWindFallCircJamewwwbEdmuZoneRHZNEnerFirsSamuEric
GardHappHearIoseNirvZoneMayfWithFIPRZoneHeinEigePaulWindZoneZoneZoneZoneZoneDiscBrenZone
ZoneMounWindGaryGarySidnXVIIMiloSennLeclArchAluTTekaThisBookBookJardFlipBeflDaliMistMBQi
OlmeSuprPROTTallDisgjazzValiCleaVictGeorJohnClimSimbWindWindWindWishSiemPhilMandChoivoir
RoryNetwStanPhotXVIIHeadNielChanMartLabaVIIIStanCharCurrFineBillrideDigiPresVeraWorlHead
LeonLadySonySonyGravJereMalyCommJillFearNapoBradDiamAfteWindEmpiPhilJeweSharMicrJeweXVII
GillJeweVIIIWordSandMoneEdmoSennSennSennwwwrXIIIpeopEnjoPaulRusJBookProfKestDoroNenaWhit
tuchkasDamiRETA