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 8605
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: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |