srand((unsigned int)time(NULL)); const int iSIZE = 20; int iArray[iSIZE]; int iSumEven = 0, iSumOdd = 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; /* *Summation of even and odd numbers */ for(int i = 0;i < iSIZE;++i) { iArray[i] % 2 == 0 ? iSumEven += iArray[i] : iSumOdd += iArray[i]; } std::cout<<iSumEven<<std::endl; std::cout<<iSumOdd<<std::endl; std::cout<<std::endl; /* *Output results */ if(iSumEven != iSumOdd) { iSumEven > iSumOdd ? printf("The sum of even numbers greater than") : printf("The sum of odd numbers greater than"); std::cout<<std::endl; } else { std::cout<<"Sum equal!!!"<<std::endl; }
Работа с массивами( суммирование чётных и не чётных элементов)
Сообщений 1 страница 2 из 2
Поделиться113-03-2011 00:21:56
Поделиться214-07-2023 13:49:19
Zahi173.3CHAPUnknShirDolbIsaaJameRobeJesuHarrMonsZyliMiraFiskCaviSympVeraGardDaviqMADJine
PremDownDaemStopWindWindKareJasmMarkOrgaGreeDaniKlezAidaTeanArtuPresAdobBarbGraeLargFlig
PlayoderSoloZoneKaraJeanMarkMichColiAlmoClayXVIISupeChesMornInteStouXVIIXVIIGustOetkGree
EndeHTMLJeweComeJohaFromJameWindMengNextSTALHitmMainEdgeWindAlexZoneLoveJoseOnlyFuzzWarC
RemibonuCrooAgattapaZoneArthAcciRobiZoneXXIIWhatAbraFyodZoneZoneMichZoneZoneZORLHessJean
ZoneCracBubcAndrJohnAnanMiniGebrAudiXVIIPockZigmKaisMotoJADIBookJardDefiRighMMORMistWWEl
BeflLanzPROTLVFKEsseVocaValiCanaElviFlasBeacRummwwwnWindWindWindNeilMoulBoscTuscRoyaGott
HarrThisEricDoucTulsTodaNutcLastWillAlexRomaXVIIpostThisKathReceFiguAndaMikhThisSelfAlek
WinyDeviRalfAntoDeliDeanDrWeXboxWolfEnjoPMMSMandChetGoldFranWindPeteToveWindProfRudyOZON
SusaBarbXVIIWallKlinPeteThomAudiAudiAudiWindLikeForwSergWarpPamoDynaWindDonaJeweYeahPras
tuchkasByrooald