Hi, I have this program in C that prints me a right character triangle but I created it in a way that it asks me for the number of rows I want to print, but what I actually want to insert is the letter that I want at the bottom, for example if I insert the number 3, it prints me:
A
BB
CCC
DDDD

BUT what I really want is to insert the letter D in order to print the triangle bellow.
this is my program, it was really hard for me to make out this I'm kind of new in this C thing. please help me.

#include<stdio.h>
#include<conio.h>
void main()
{
 int i,j,n;
 char c;
 clrscr();
 printf("Enter the value of n:");
 scanf("%d",&n);
 c=65;
 for(i=0;i<=n;i++)
 {
  for(j=0;j<=i;j++)
  {
   printf("%c",c);


  }
       c++;
 printf("\n\n");
 }
getch();
}

This might help:

#include<stdio.h>
#include<conio.h>
#include <ctype.h>
using namespace std;
void main()
{
    int i,j;
    char n;
    printf("Enter the target letter: ");

    //get the target character
    scanf("%c",&n);

    //convert it to upper case
    n= toupper(n);

    //start the loop.  Notice starting i at 65 eliminates the need for another char variable
    for(i=65; i<=n; i++)
    {
        for(j=0; j<=i-65; j++)
        {
            //char is basically an int, so an int can be implicitly cast as a char                
            printf("%c",i);
        }

        printf("\n\n");
    }
    _getch();
}

Edited 3 Years Ago by tinstaafl

This article has been dead for over six months. Start a new discussion instead.