Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <sstream>
- using namespace std;
- int long long Fibo(int n);
- string output_formatted_string(long long num);
- int main() {
- int n = 0;
- cout << "Enter a number: ";
- cin >> n;
- string s = output_formatted_string(Fibo(n));
- cout << "Fibo(" << n << ") = " << s << endl;
- system("PAUSE");
- return 0;
- }
- long long Fibo(int n) {
- if (n < 2)
- return 1;
- long long temp1 = 1;
- long long temp2 = 1;
- long long total = 0;
- while (n-- > 1) {
- total = temp1 + temp2;
- temp2 = temp1;
- temp1 = total;
- }
- return total;
- }
- #define GROUP_SEP ','
- #define GROUP_SIZE 3
- string output_fomratted_string(long long num) {
- // Read data intop string s.
- stringstream temp, out;
- temp << num;
- string s = temp.str();
- // Write first characters, in front of
- // first seperator (GROUP_SEP).
- int n = s.size() % GROUP_SIZE;
- int i = 0;
- if (n > 0 && s.size() > GROUP_SIZE) {
- out << s.substr(i, n) << GROUP_SEP;
- i += n;
- }
- // Handle all the remaining groups
- n = s.size() / GROUP_SIZE - 1;
- while (n-- > 0) {
- out << s. substr(i, GROUP_SIZE) << GROUP_SEP;
- i += GROUP_SIZE;
- }
- out << s.substr(i); // Write the rest of the digits.
- return out.str(); // Convert stream -> string.
- }
- 1>------ Build started: Project: NoFear2, Configuration: Debug x64 ------
- 1>Build started 2/22/2014 6:47:00 PM.
- 1>InitializeBuildStatus:
- 1> Touching "x64DebugNoFear2.unsuccessfulbuild".
- 1>ClCompile:
- 1> All outputs are up-to-date.
- 1> fibo.cpp
- 1>fibo.cpp(58): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
- 1>ManifestResourceCompile:
- 1> All outputs are up-to-date.
- 1>fibo.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl output_formatted_string(__int64)" (?output_formatted_string@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_J@Z) referenced in function main
- 1>C:UsersdirectnirvanaDocumentsVisual Studio 2010ProjectsNoFear2x64DebugNoFear2.exe : fatal error LNK1120: 1 unresolved externals
- 1>
- 1>Build FAILED.
- 1>
- 1>Time Elapsed 00:00:01.17
- ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
- int long long Fibo(int n);
- long long Fibo(int n);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement