I just strating taking C class and still learning. I couldn't come up with the output like the one below:
A
ABA
ABCBA
ABCDCDA
ABCDEDCBA
Here is what I tried: -
#include<stdio.h>
-
#define ROW 6
-
#define RSIZE 6
-
#define ASCEND 4
-
#define SPACE 6
-
#define DESCEND 4
-
int main()
-
{
-
char ch,letter, column;
-
int row;
-
-
printf("Please enter an UPPERCASE letter:");
-
scanf("%c",&ch);
-
-
for (row = 1 ; row < ROW ; row ++)
-
{
-
for (column = 1; column < SPACE - row; column++)
-
printf(" ");
-
{
-
for (letter = row ; letter >= 1 ; letter --)
-
printf("%c", ch);
-
printf("\n");
-
}
-
}
-
fflush(stdin);
-
getchar();
-
return 0;
-
}// main
-
Thanks for you help
shulapi
8 8663
I just strating taking C class and still learning. I couldn't come up with the output like the one below:
A
ABA
ABCBA
ABCDCDA
ABCDEDCBA
Here is what I tried: -
#include<stdio.h>
-
#define ROW 6
-
#define RSIZE 6
-
#define ASCEND 4
-
#define SPACE 6
-
#define DESCEND 4
-
int main()
-
{
-
char ch,letter, column;
-
int row;
-
-
printf("Please enter an UPPERCASE letter:");
-
scanf("%c",&ch);
-
-
for (row = 1 ; row < ROW ; row ++)
-
{
-
for (column = 1; column < SPACE - row; column++)
-
printf(" ");
-
{
-
for (letter = row ; letter >= 1 ; letter --)
-
printf("%c", ch);
-
printf("\n");
-
}
-
}
-
fflush(stdin);
-
getchar();
-
return 0;
-
}// main
-
Thanks for you help
shulapi
First, Welcome to TSDN!!! We hope you learn a lot during your stay.
Second, the next time you post, please be sure and choose a forum appropriate to the topic of your thread. The "Member Introductions" forum is not the place for a C programming question when there is a C programming forum.
I will move this thread over there now.
Regards and Happy Holidays!
Jeff
Okay, so you have the first half of the program down. Why are you asking for just one letter? I'd say it looks more like levels - you put in the number of levels, and then it prints out the appropriate letters per level. For instance, the the first level prints out one letter, the second level prints out three letters, and the third level prints out five, fourth prints seven...
Are you seeing a pattern? You'd have your loop as it is now, but it would increment through the alphabet until it got halfway through, and then it would decrement back to its original spot.
First, Welcome to TSDN!!! We hope you learn a lot during your stay.
Second, the next time you post, please be sure and choose a forum appropriate to the topic of your thread. The "Member Introductions" forum is not the place for a C programming question when there is a C programming forum.
I will move this thread over there now.
Regards and Happy Holidays!
Jeff
Thanks Jeff. I will make sure that won't happen again. Just new to the forum.
Okay, so you have the first half of the program down. Why are you asking for just one letter? I'd say it looks more like levels - you put in the number of levels, and then it prints out the appropriate letters per level. For instance, the the first level prints out one letter, the second level prints out three letters, and the third level prints out five, fourth prints seven...
Are you seeing a pattern? You'd have your loop as it is now, but it would increment through the alphabet until it got halfway through, and then it would decrement back to its original spot.
Thanks for your help sicarie. Can you please clarify it a bit more for me. If you run the program the way it is, it only outputs the left half of the pyramid without changing the letters. For instance if my input is the letter E, the output looks like the following: My problem is gettting the full pyramid with ascending descending letters. I will appreciate for your help.
E
E E
EEE
EEEE
EEEEE
Well,
If you have the algo that generates the half-pyramid already it's pretty easy to make a "mirror image" of it and output first the mirror image and then the actual pyramid that you have there. It's also easy do that (output both pyramids at the same time) with a little more efford in these for loops.
Also and advice, in order to get rid of the annoying uppercase/lowercase letter issue (in the cases where you don't want the input to be case-sensive as it's this one) you can use the following in order to convert the input value (whether it is lowercase or uppercase) to uppercase or lowercase depending on your needs -
char pKey;
-
-
pKey = getch();
-
-
// your check or whatever
-
if ( toupper(pKey) == 'K' /* can be anything else */ )
-
}
-
// do stuff
-
}
-
also if you have while loops or anything else that repeats :p just to avoid continued calls to that function, if you don't change the value before the check do the following: -
char pKey;
-
-
pKey = getch();
-
-
pKey = toupper(pKey) ;
-
// your check or whatever
-
while ( pKey == 'K' /* can be anything else */ )
-
}
-
// do stuff
-
}
-
hope this helped!
Well,
If you have the algo that generates the half-pyramid already it's pretty easy to make a "mirror image" of it and output first the mirror image and then the actual pyramid that you have there. It's also easy do that (output both pyramids at the same time) with a little more efford in these for loops.
Also and advice, in order to get rid of the annoying uppercase/lowercase letter issue (in the cases where you don't want the input to be case-sensive as it's this one) you can use the following in order to convert the input value (whether it is lowercase or uppercase) to uppercase or lowercase depending on your needs -
char pKey;
-
-
pKey = getch();
-
-
// your check or whatever
-
if ( toupper(pKey) == 'K' /* can be anything else */ )
-
}
-
// do stuff
-
}
-
also if you have while loops or anything else that repeats :p just to avoid continued calls to that function, if you don't change the value before the check do the following: -
char pKey;
-
-
pKey = getch();
-
-
pKey = toupper(pKey) ;
-
// your check or whatever
-
while ( pKey == 'K' /* can be anything else */ )
-
}
-
// do stuff
-
}
-
hope this helped!
Good advice, except I would never use getch() as it is non-standard and will break stuff. Stick with standard functions.
Well I said what I said because getch() is simple and convienient ;). Sure, you could also use scanf but oh, well it's up to you ;).
Well I said what I said because getch() is simple and convienient ;). Sure, you could also use scanf but oh, well it's up to you ;).
much appreciated Andr3w and sicarie
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Micheal Artindale |
last post by:
I am looking at creating list of letter combinations.
letters a-h
6 letters per combination
letter can repeat its self in the combination, but not next to its self
and, a series of letter can...
|
by: Andrew Westgarth |
last post by:
Hi all,
i'm struggling with a page idea I have.
I need to write a page with an A to Z list of available schools in the area.
I only want to display the letters in the A to Z which have school...
|
by: Kosmos |
last post by:
Hey :) hopefully someone can help me with this...I decided to take on the task of programming an access database for my legal co-op/internship...I'm studying law and music production on the...
|
by: virtualadepts |
last post by:
I spent quite a bit of work trying to get this to format on google
groups, so let me know if it needs explination. Basicly the tree sorts
randomly, and can start from any number on the pyramid. ...
|
by: i m gr8 |
last post by:
Hello,
I need to make a pyramid 20 lines long showing Xs like this:
X
XX
XXX
XXXX
and so on .
I have made this code so far:
|
by: Kahlia |
last post by:
Hi. I am trying to print a pyramid of asterisks using recursion so that the recursive function takes in an integer and prints that number of lines of asterisks and then reverses, eg:
*
...
|
by: rashee |
last post by:
hello everybody,
i want to print the pyramid of numbers in the following manner.
1
212
32123
4321234
and so on depending on the no of rows.
plz help me out.
|
by: n8kindt |
last post by:
hey guys,
i'm using access 2007. i'm not happy with my solution to the following problem so i'm hoping one of you guys has a better idea. my solution would require use of multiple valued fields...
|
by: process |
last post by:
http://projecteuler.net/index.php?section=problems&id=18
def recur(tree, pos):
if not tree:
return
else:
return ] + recur(tree, pos)] + \
] + recur(tree, pos+1)]
|
by: Gn02 |
last post by:
Hi im noob in JAVA could someone explain to me how to make this program
for loop..
asterisk pyramid sideward
.. plss answer me i want to learn it
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |