Question
ANSWER IN C PLEASE (:

ew History Bookmarks Window Help 13.16. Loops E ry> ECE 270 home > 13.16 Loops-Ex4 zyBooks catalog TO.TU LOOo Write a program that prints a pattern like the ones shown below Ask the user to input the letter that goes in the middle of the last row in the pyramid (uppercase or lowercase). The pattern should extend to the character entered. In the Example 1, the pattern is the result from an input value of E. Consider the alphabet as a continuous list such that before the A comes Z (see example 2) Hint: Use nested loops Example 1: Input Output Example 2: nput Ouxput 5 6 7 8
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<iostream>
using namespace std;
int ascc(int n,int prev);
int ascc1(int n);
int ascc2(int n);
int main()
{
int i,j,k,l,m,asc,ch1,ch2;
char c;
printf("Enter a character:");
cin>>c;
int as=c;

for(i=1;i<=5;i++)
{
        for(j=1;j<=5-i;j++)
        {
                cout<<" ";
        }
        ch1=as-4;
        for(k=1;k<=i;k++)
        {
                cout<<(char)ascc(ch1,as);
                ch1++;
        }
        ch2=ch1-2;
        for(l=1;l<i;l++)
        {
                cout<<(char)ascc(ch2,as);
                ch2--;
        }
        cout<<"\n";
}
}
int ascc(int n,int prev)
{
if(prev>=65&&prev<=90)
return(ascc1(n));
else
return(ascc2(n));
}
int ascc1(int n)
{
        if((n>=65 && n<=90)||(n>=97&&n<=122))
                return(n);
        else if(n<65)
                return(n+26);
        else if (n>122)
                return(n-26);
        else if (n>90 && n<95)
                return(n-26);
        else if(n>=93 && n<97)
                return(n+26);
}
int ascc2(int n)
{
        if((n>=65 && n<=90)||(n>=97&&n<=122))
                return(n);
        else if(n<65)
                return(n+26);
        else if (n>122)
                return(n-26);
        else if(n>=93 && n<97)
                return(n+26);
}
Add a comment
Know the answer?
Add Answer to:
ANSWER IN C PLEASE (: ew History Bookmarks Window Help 13.16. Loops E ry> ECE 270...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C programming language have a program request the user to enter an uppercase letter. Use...

    In C programming language have a program request the user to enter an uppercase letter. Use nested loops to produce a pyramid pattern like this: The pattern should extend to the character entered. For example, the preceding pattern would result from an input value of E. Hint: Use an outer loop to handle the rows. Use three inner loops in a row, one to handle the spaces, one for printing letters in ascending order, and one for printing letters in...

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT