formatting source-code for d7af6fdc8c

This commit is contained in:
github-actions
2020-05-29 23:26:30 +00:00
parent edb3d51ec2
commit 7ad1f171c1
176 changed files with 5342 additions and 4288 deletions

View File

@@ -21,41 +21,50 @@
* \param [in] b second number in string to add
* \returns sum as a std::string
*/
std::string add(std::string a, std::string b) {
std::string add(std::string a, std::string b)
{
std::string temp = "";
// carry flag
int carry = 0;
// fills up with zeros
while (a.length() < b.length()) {
while (a.length() < b.length())
{
a = "0" + a;
}
// fills up with zeros
while (b.length() < a.length()) {
while (b.length() < a.length())
{
b = "0" + b;
}
// adds the numbers a and b
for (int i = a.length() - 1; i >= 0; i--) {
for (int i = a.length() - 1; i >= 0; i--)
{
char val = static_cast<char>(((a[i] - 48) + (b[i] - 48)) + 48 + carry);
if (val > 57) {
if (val > 57)
{
carry = 1;
val -= 10;
} else {
}
else
{
carry = 0;
}
temp = val + temp;
}
// processes the carry flag
if (carry == 1) {
if (carry == 1)
{
temp = "1" + temp;
}
// removes leading zeros.
while (temp[0] == '0' && temp.length() > 1) {
while (temp[0] == '0' && temp.length() > 1)
{
temp = temp.substr(1);
}
@@ -65,11 +74,13 @@ std::string add(std::string a, std::string b) {
/** Fibonacci iterator
* \param [in] n n^th Fibonacci number
*/
void fib_Accurate(uint64_t n) {
void fib_Accurate(uint64_t n)
{
std::string tmp = "";
std::string fibMinus1 = "1";
std::string fibMinus2 = "0";
for (uint64_t i = 0; i < n; i++) {
for (uint64_t i = 0; i < n; i++)
{
tmp = add(fibMinus1, fibMinus2);
fibMinus2 = fibMinus1;
fibMinus1 = tmp;
@@ -78,7 +89,8 @@ void fib_Accurate(uint64_t n) {
}
/** main function */
int main() {
int main()
{
int n;
std::cout << "Enter whatever number N you want to find the fibonacci of\n";
std::cin >> n;