Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.  
  8. int long long Fibo(int n);
  9. string output_formatted_string(long long num);
  10.  
  11. int main() {
  12. int n = 0;
  13. cout << "Enter a number: ";
  14. cin >> n;
  15. string s = output_formatted_string(Fibo(n));
  16. cout << "Fibo(" << n << ") = " << s << endl;
  17. system("PAUSE");
  18. return 0;
  19. }
  20.  
  21. long long Fibo(int n) {
  22. if (n < 2)
  23. return 1;
  24. long long temp1 = 1;
  25. long long temp2 = 1;
  26. long long total = 0;
  27. while (n-- > 1) {
  28. total = temp1 + temp2;
  29. temp2 = temp1;
  30. temp1 = total;
  31. }
  32. return total;
  33. }
  34.  
  35. #define GROUP_SEP ','
  36. #define GROUP_SIZE 3
  37.  
  38. string output_fomratted_string(long long num) {
  39.  
  40. // Read data intop string s.
  41.  
  42. stringstream temp, out;
  43. temp << num;
  44. string s = temp.str();
  45.  
  46. // Write first characters, in front of
  47. // first seperator (GROUP_SEP).
  48.  
  49. int n = s.size() % GROUP_SIZE;
  50. int i = 0;
  51. if (n > 0 && s.size() > GROUP_SIZE) {
  52. out << s.substr(i, n) << GROUP_SEP;
  53. i += n;
  54. }
  55.  
  56. // Handle all the remaining groups
  57.  
  58. n = s.size() / GROUP_SIZE - 1;
  59. while (n-- > 0) {
  60. out << s. substr(i, GROUP_SIZE) << GROUP_SEP;
  61. i += GROUP_SIZE;
  62. }
  63. out << s.substr(i); // Write the rest of the digits.
  64. return out.str(); // Convert stream -> string.
  65. }
  66.  
  67. 1>------ Build started: Project: NoFear2, Configuration: Debug x64 ------
  68. 1>Build started 2/22/2014 6:47:00 PM.
  69. 1>InitializeBuildStatus:
  70. 1> Touching "x64DebugNoFear2.unsuccessfulbuild".
  71. 1>ClCompile:
  72. 1> All outputs are up-to-date.
  73. 1> fibo.cpp
  74. 1>fibo.cpp(58): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
  75. 1>ManifestResourceCompile:
  76. 1> All outputs are up-to-date.
  77. 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
  78. 1>C:UsersdirectnirvanaDocumentsVisual Studio 2010ProjectsNoFear2x64DebugNoFear2.exe : fatal error LNK1120: 1 unresolved externals
  79. 1>
  80. 1>Build FAILED.
  81. 1>
  82. 1>Time Elapsed 00:00:01.17
  83. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  84.  
  85. int long long Fibo(int n);
  86.  
  87. long long Fibo(int n);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement