Last active
December 20, 2015 05:39
-
-
Save bor2com/6079692 to your computer and use it in GitHub Desktop.
Sample sources.
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
// Just printing a message. | |
#include <iostream> | |
using namespace std; | |
int main() { | |
cout << "Hello" << " " << "world"; | |
cout << "Hello world"; | |
return 0; | |
} |
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
// Demonstration of modulo capabilities. | |
#include <iostream> | |
using namespace std; | |
int main() { | |
int a, b; | |
a = 10; | |
b = 7; | |
cout << a / b << endl; | |
cout << a % b << endl; | |
return 0; | |
} |
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
// Popping next hour on a 12-hour clock. | |
#include <iostream> | |
using namespace std; | |
int main() { | |
int a; | |
cin >> a; | |
a = a - 1; | |
a = a + 1; | |
a = a % 12; | |
a = a + 1; | |
cout << a << endl; | |
return 0; | |
} |
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
// Paying with a minimum amount of bills. | |
#include <iostream> | |
using namespace std; | |
int main() { | |
int bills[] = { 200, 100, 50, 20, 10, 5, 2, 1 }, n, i; | |
i = 0; | |
cin >> n; | |
while (n != 0) { | |
while (bills[i] > n) { | |
i = i + 1; | |
} | |
cout << bills[i] << ' '; | |
n = n - bills[i]; | |
} | |
return 0; | |
} |
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
// This one shows why the naive approach is wrong. | |
#include <iostream> | |
using namespace std; | |
int main() { | |
int bills[] = { 5, 4, 1 }, n, i; | |
cin >> n; | |
while (n != 0) { | |
i = 0; | |
while (bills[i] > n) { | |
i = i + 1; | |
} | |
cout << bills[i] << ' '; | |
n = n - bills[i]; | |
} | |
return 0; | |
} |
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
// Program for calculating the sum of an integer sequence. | |
#include <iostream> | |
using namespace std; | |
int main() { | |
int marks[10], n, i, sum; | |
// Reading stuff. | |
cin >> n; | |
i = 0; | |
while (i < n) { | |
cin >> marks[i]; | |
i = i + 1; | |
} | |
// Summing up. | |
sum = 0; | |
i = 0; | |
while (i < n) { | |
sum = sum + marks[i]; | |
i = i + 1; | |
} | |
cout << sum; | |
return 0; | |
} |
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
// It figurs out the sum of digits. | |
#include <iostream> | |
using namespace std; | |
int main() { | |
int kriakoziabra, sum; | |
sum = 0; | |
cin >> kriakoziabra; | |
while (kriakoziabra != 0) { | |
sum = sum + kriakoziabra % 10; // Retrieving the last digit. | |
kriakoziabra = kriakoziabra / 10; // Chopping it off. | |
} | |
cout << sum; // Voila! | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment