fork download
  1. #include <iostream>
  2. #include <sstream>
  3. using namespace std;
  4.  
  5. int main() {
  6. char top_line[10][4] = {"###", " #", "## ", "###", "# #", " ##", "# ", "###", "###", "###" };
  7. char middle_line[10][4] = {"# #", " #", " # ", " ##", "###", " # ", "###", " #", "###", "###" }; //make similar to top_line;
  8. char bottom_line[10][4] = {"###", " #", " ##", "###", " #", "## ", "###", " #", "###", " #" }; //make similar to top_line;
  9. printf("Enter a number:");
  10. int n;
  11. scanf("%d", &n);
  12. int n_copy = n;
  13. // We count the number of digits in n;
  14. int digits = 1;
  15. while(n) {
  16. n/=10;
  17. digits *= 10;
  18. }
  19. digits = digits/10;
  20. n = n_copy;
  21. stringstream line1, line2, line3;
  22. while (n) {
  23. int d = n / digits;
  24. n = n % digits;
  25. digits /= 10;
  26. line1 << top_line[d] << " ";
  27. line2 << middle_line[d] << " ";
  28. line3 << bottom_line[d] << " ";
  29. }
  30. cout <<endl << line1.str() << endl << line2.str() << endl << line3.str() << endl;
  31. }
Success #stdin #stdout 0s 16064KB
stdin
78934
stdout
Enter a number:
###   ###   ###   ###   # #   
  #   ###   ###    ##   ###   
  #   ###     #   ###     #