Ask Question
19 October, 08:41

Input a number [1-50] representing the size of the shape and then a character [x, b, f] which represents the shape i. e. x->cross, b->backward slash, or f->forward slash. Here are 4 examples which give the 2 inputs with the shape of the result directly below. Note: Even number outputs are different from odd.

+3
Answers (1)
  1. 19 October, 11:57
    0
    C+ + code given below with appropriate comments

    Explanation:

    pattern. cpp

    #include

    using namespace std;

    void printCross (int n)

    {

    int i, j, k;

    if (n%2) / /odd number of lines

    {

    for (int i=n; i>=1; i--)

    {

    for (int j=n; j>=1; j--)

    cout<<"/n";

    }

    }

    else / /even number of lines

    {

    for (int i=1; i<=n; i++)

    {

    for (int j=1; j<=n; j++)

    {

    if (j==i || j= = (n-i+1))

    {

    cout<<" "<
    }

    else

    cout<<" ";

    }

    cout<<"/n";

    }

    }

    }

    void printForwardSlash (int n)

    {

    if (n%2)

    {

    for (int i=n; i>=1; i--)

    {

    for (int j=n; j>=1; j--)

    {

    if (j==n-i+1)

    {

    cout<
    }

    else

    cout<<" ";

    }

    cout<<"/n";

    }

    }

    else

    {

    for (int i=1; i<=n; i++)

    {

    for (int j=1; j<=n; j++)

    {

    if (j= = (n-i+1))

    {

    cout<
    }

    else

    cout<<" ";

    }

    cout<<"/n";

    }

    }

    }

    void printBackwardSlash (int n)

    {

    if (n%2) / / odd number of lines

    {

    for (int i=n; i>=1; i--)

    {

    for (int j=n; j>=1; j--)

    {

    if (j==i)

    {

    cout<
    }

    else

    cout<<" ";

    }

    cout<<"/n";

    }

    }

    else / /even number of lines

    {

    for (int i=1; i<=n; i++)

    {

    for (int j=1; j<=n; j++)

    {

    if (j==i)

    {

    cout<
    }

    else

    cout<<" ";

    }

    cout<<"/n";

    }

    }

    }

    int main ()

    int num;

    char ch;

    cout<<"Create a numberes shape that can be sized."<
    cout<<"Input an integer [1,50] and a character [x, b, f]."<
    cin>>num>>ch;

    if (ch=='x'
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Input a number [1-50] representing the size of the shape and then a character [x, b, f] which represents the shape i. e. x->cross, ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers