Guest User

Untitled

a guest
Jul 15th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /*
  2. * Program3A.cpp
  3. *
  4. * Created on: Mar 26, 2012
  5. * Author: Brian
  6. */
  7.  
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. void writeLine(char, int);
  12. void writeBlock(char, int, int);
  13. int Triangle(int);
  14. int totalNums(int);
  15.  
  16. int main()
  17. {
  18. char aChar;
  19. int anInt;
  20. // Start writeLine
  21. cout << "Enter character: ";
  22. cin >> aChar;
  23. cout << "Enter the number of of characters: ";
  24. cin>> anInt;
  25.  
  26. writeLine(aChar, anInt);
  27. cout<< endl;
  28. // End of writeLine
  29.  
  30. // Start writeBlock
  31. int num2;
  32. cout << "How many lines? ";
  33. cin >> num2;
  34. writeBlock(aChar, anInt, num2);
  35. cout<< endl;
  36. //End of writeBlock
  37. return 0;
  38. }
  39.  
  40. void writeLine(char a, int b)
  41. {
  42. if (b >= 1)
  43. {
  44. cout << a;
  45. writeLine(a, b - 1);
  46. }
  47.  
  48. void writeBlock(char a , int num1 , int num2)
  49. {
  50. if (num2 >= 1)
  51. {
  52. writeLine(a, b);
  53. cout << "\n";
  54. writeBlock(a, num1, num2 - 1);
  55. }
  56. }
  57. }
  58.  
  59. int Triangle(int x)
  60. {
  61. if ( x == 0)
  62. return 0;
  63.  
  64. else
  65. return x + Triangle(x-1);
  66. }
  67.  
  68. int totalNums(int g)
  69. {
  70. if (g / 10 == 0)
  71. {
  72. return g;
  73. }
  74. else
  75. {
  76. return (g % 10) + totalNums(g / 10);
  77. }
  78. }
Add Comment
Please, Sign In to add comment