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)

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;

printf("Input:");
scanf("%c", &input);
printf("Base:");
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.

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);
for(i=1;i<=n;i++)
{
while(j<=2*i-1)
{
// Fill this part
}
j=1;
printf("\n");
}
}

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

//Assume that user input is 3
for(i=0;i<=3;i++)
{
if(toggle==0)
{
display(num);
num=num+2;
toggle=1;
}
else if(toggle==1)
{
// Similarly write this one
}
}

return 1;
}``````