-
Output from nested loops
Hello, I,m trying to get this output from some nested loops, which is becoming very frustrating. So far this is what i have.
Entering D:
A
AB
ABC
ABCD
whereas i need the following type of output:
A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
Except not like this but in pyramid shape.
I've been at this for hours but can't figure it out-any help would be much appreciated!!
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int x,y;
char ch,in;
printf("Get a Capital character: ");
scanf("%c",&in);
for (x = 'a'; x <= in; x++)
{
for (ch = 'a';ch <= x;ch++)
printf("%c",toupper(ch));
printf("\n");
}
return 0;
}
-
#include <stdio.h>
#include <ctype.h>
int main(void)
{
int p,q,x,y;
char ch,in;
printf("\nEnter a lower case letter:\n\n");
fflush(stdout);
printf("\nGet a Capital character: \n\n");
scanf("%c",&in);
p=in-'a'+1; /* position in alphabet of in i.e. a=1,b=2,c=3... */
for(x='a',q=p;x<=in;x++)
{
for(y=1;y<q;y++) printf(" "); /* inserts the relevant amount of spaces*/
for(ch='a';ch<=x;ch++) printf("%c",toupper(ch));
for(ch=x-1;ch>='a';ch--) printf("%c",toupper(ch));
printf("\n");
q--;
}
return 0;
}
-
ams80 thanks for your help!! i really do appreciate your help
greatly.
Izaak