Created
December 12, 2017 18:55
-
-
Save tehp/ad0b6ec258286b99449b1e4d13e0c495 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.cpp | |
// algoFinal | |
// | |
// Created by Mac Craig on 2017-12-12. | |
// Copyright © 2017 mcknzcrg. All rights reserved. | |
// | |
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int algo2(int n) { | |
int coins = 0; | |
int value = 0; | |
while (value <= (n-7)) { | |
coins++; | |
value = value + 7; | |
} | |
while (value <= (n-6)) { | |
coins = coins + 2; | |
value = value + 6; | |
} | |
while (value <= (n-4)) { | |
coins++; | |
value = value + 4; | |
} | |
while (value <= (n-3)) { | |
coins++; | |
value = value + 3; | |
} | |
while (value <= (n-1)) { | |
coins++; | |
value++; | |
} | |
return coins; | |
} | |
int main() | |
{ | |
cout << "result: " << algo2(20) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment