Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Program3A.cpp
- *
- * Created on: Mar 26, 2012
- * Author: Brian
- */
- #include <iostream>
- using namespace std;
- void writeLine(char, int);
- void writeBlock(char, int, int);
- int Triangle(int);
- int totalNums(int);
- int main()
- {
- char aChar;
- int anInt;
- // Start writeLine
- cout << "Enter character: ";
- cin >> aChar;
- cout << "Enter the number of of characters: ";
- cin>> anInt;
- writeLine(aChar, anInt);
- cout<< endl;
- // End of writeLine
- // Start writeBlock
- int num2;
- cout << "How many lines? ";
- cin >> num2;
- writeBlock(aChar, anInt, num2);
- cout<< endl;
- //End of writeBlock
- return 0;
- }
- void writeLine(char a, int b)
- {
- if (b >= 1)
- {
- cout << a;
- writeLine(a, b - 1);
- }
- void writeBlock(char a , int num1 , int num2)
- {
- if (num2 >= 1)
- {
- writeLine(a, b);
- cout << "\n";
- writeBlock(a, num1, num2 - 1);
- }
- }
- }
- int Triangle(int x)
- {
- if ( x == 0)
- return 0;
- else
- return x + Triangle(x-1);
- }
- int totalNums(int g)
- {
- if (g / 10 == 0)
- {
- return g;
- }
- else
- {
- return (g % 10) + totalNums(g / 10);
- }
- }
Add Comment
Please, Sign In to add comment