I need to create a christmast tree which takes R value from user then output on console
a Christmas tree in which last part height equals R.
The tree consists of triangles of heights
from 1 to n.The shape must look like (for R=4)


thanks in advance...

You're welcome in retrospect.

Why did you post this? What kind of response are you expecting? you didn't even ask a question.

sorry for late ... I got problem with internet , I just created a template which generates last part of that code (equ. triangle)

#include <stdio.h>

int main (int argc,char* argv[])

    char input;
    int base,a,b;

    scanf("%c", &input);
    scanf("%i", &base);

    for ( a = 1; a <= base; a++)
        for ( b = 0; b < base-a; b++ )
            putchar(' ');
        for ( b = 0; b < 2*a - 1; b++ )
            putchar( input );
        putchar( '\n' );
    return 0;

in this code input is the character of triangle base is the number of lenght ...
How can I get it converted into christmas tree that I need ?



I think you need to consider this more mathematically..

also you can't build from the base up because you're outputting from top down.

in your examples
you're making r number of triangles. (r=4)

through each iteration you add one level n+1. (starting w/ n=0)

through each level you're putting 2n-1 "X"'s

Here is another idea... It will probably get you started but you have to do more work on it to get the finish product

void display(int n)
        // Right now all the X will be left justified. You have to figure out how to include spaces.  
        int i=0,j=1,num=1;

        printf("In display %d\n",n);
                      // Fill this part

int main(int argc, char* argv[])
        int i=0,num=1,num1=2,toggle=0;

        //Assume that user input is 3 
                else if(toggle==1)
                        // Similarly write this one

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