jeudi 12 mars 2015

Character patterns in C

I m trying to get the following character pattern as follows by only using "for" or "while" loops but no "if" or "if-else" statements: _ (this one is a blank space) BA CBA DCBA EDCBA Its dificult for me to figure out a way to make the first character appear as blank space or represent it even as a null character. Below is my code: #include #include



int main()
{
char ch[6], j='\0';
int p,q,n,i;
printf("Enter a character\n");
for (n = 0; n < 5; n++)
{
scanf_s(" %c", &ch[n], 1);
}
printf("\n");
for (i = 4; i >= 0; i--)
{
for (p = 4; p >= i; p--)
{
printf("%c", ch[p+1]-1);

}
printf("\n");
}

_getch();
return 0;
}


I cannot figure out where m I going wrong.


Aucun commentaire:

Enregistrer un commentaire