/* Write a program, that asks user to input an integer in decimal form. After that, program asks user should result be printed in hexadecimal form (answer will be either 'y' or 'n'). Flip the 3rd least significant bit of the integer (from 1 to 0 and vice versa) and print if user wanted result in hexadecimal form, print it as such. Otherwise print result in decimal form. */ #include #include using namespace std; main(int argc, char *argv[]) { char vastaus; int luku; cout << "Anna luku: "; cin >> luku; cout << "Tulostetaanko vastaus hexana (y/n):"; cin >> vastaus; if (vastaus == 'y') // kysytään käytttäjältä näytrtäänkö luvut hexana cout << hex << luku << endl; // tulostetaan alkuperäinen luku hexana // maskataan syötetty luku XOR-operaatiolla // maski annetaan hexana (0x4 -> 0b0100 -> 4) luku = luku ^ 0x4; if (vastaus == 'y') cout << hex << luku << endl; // tulostetaan maskattu luku hexana else cout << luku << endl; // jos y/n kysymykseen vastattiin muuta kuin y, // tulostetaan maskattu luku desimaali muodossa system("PAUSE"); return EXIT_SUCCESS; } ************************************************************************************************* /* Write a program that asks user to input an amount of money from 0.00-10.00 € (decimals are allowed). Program must then determine what is the amount of 20c, 10c, 5c and 1c coins from which the given amount is formed. Program must print number of each coins needed, and total amount of them. Number of coins must always be minimum */ #include #include #include using namespace std; int main(void) { float rahat, rahat2; int XXs=0, Xs=0, VIs=0, Is=0; cout << "Anna rahamaara (0.00 - 10.00 euroa): "; cin >> rahat; rahat2 = rahat; while (rahat > 0.00 ){ if(fabs(fmod(rahat, 0.2)) >= 0){ rahat -= 0.2; XXs++; }else if(fabs(fmod(rahat, 0.1)) >= 0){ rahat -= 0.1; Xs++; }else if(fabs(fmod(rahat, 0.05)) >= 0){ rahat -= 0.05; VIs++; }else if(fabs(fmod(rahat, 0.01)) >= 0){ rahat -= 0.01; Is++; } } cout << "Antamasi rahamaara oli " << rahat2 << " euroa. Rahat 20c, 10c, 5c, ja 1c kolikkoina:" << endl; cout << "20c " << XXs << " kpl" << endl; cout << "10c " << Xs << " kpl" << endl; cout << "5c " << VIs << " kpl" << endl; cout << "1c " << Is << " kpl" << endl; system("PAUSE"); return 0; }