Generate Christmas Tree
Keep the scope of variables to a minimum

Since C99 we are allowed to mix declaration and code. At the moment, you have i, j, rest and so on in scope, even if day is out of the specification. That can lead to hard to find errors, for example if we accidentally use i++ where i isn't used.

Late declaration makes it easier to copy our code into other blocks also, but more on that later. So instead, let's push the declaration as late as possible and limit the scope:

#include&lt;stdio.h&gt;

int main(){
    int day;
    scanf("%d",&amp;day);

    //Check for exceptions
    if(day&lt;=1){
        printf("You cannot generate christmas tree");
        return 0;
    }
    else if(day&gt;20){
        printf("Tree is no more");
        return 0;
    }

    // printf("Heres Your Christmas Tree:\n\n");

    // For first part
    int leaves=1;
    int branches=day+1;
    int max_leaves = 1+(branches-1)*2; // Arithmetic Progression
    for(int i=1;i&lt;=branches;i++){
        for(int j=i;j&lt;=max_leaves/2;j++){
            printf(" ");
        }
        for(int j=1;j&lt;=leaves;j++){
            printf("*");
        }
        printf("\n");
        leaves=leaves+2;
    }

    // For remaining parts
    branches=branches-2;
    for(int rest=1;rest&lt;=day-2;rest++){
        leaves=3;
        for(int i=2;i&lt;=branches+1;i++){
            for(int j=i;j&lt;=max_leaves/2;j++){
                printf(" ");
            }
            for(int j=1;j&lt;=leaves;j++){
                printf("*");
            }
            printf("\n");
            leaves=leaves+2;
        }
        branches--;
    }

    // For stand
    for(int i=1;i&lt;=2;i++){
        for(int j=1;j&lt;=max_leaves/2;j++){
            printf(" ");
        }
        printf("*\n");
    }

    return 0;
}


Use whitespace to scan code quickly

Now that we've introduced late declarations, let us add some whitespace between operators. Gone are the days where bytes in source code where expensive. Unless you intend write-only code, make code easy to read. Debugging is much nicer in well-written and spaced code:

#include &lt;stdio.h&gt;

int main() {
    int day;
    scanf("%d", &amp;day);

    // Check for exceptions
    if (day &lt;= 1) {
        printf("You cannot generate christmas tree");
        return 0;
    } else if (day &gt; 20) {
        printf("Tree is no more");
        return 0;
    }

    // printf("Heres Your Christmas Tree:\n\n");

    // For first part
    int leaves = 1;
    int branches = day + 1;
    int max_leaves = 1 + (branches - 1) * 2; // Arithmetic Progression
    for (int i = 1; i &lt;= branches; i++) {
        for (int j = i; j &lt;= max_leaves / 2; j++) {
            printf(" ");
        }
        for (int j = 1; j &lt;= leaves; j++) {
            printf("*");
        }
        printf("\n");
        leaves = leaves + 2;
    }

    // For remaining parts
    branches = branches - 2;
    for (int rest = 1; rest &lt;= day - 2; rest++) {
        leaves = 3;
        for (int i = 2; i &lt;= branches + 1; i++) {
            for (int j = i; j &lt;= max_leaves / 2; j++) {
                printf(" ");
            }
            for (int j = 1; j &lt;= leaves; j++) {
                printf("*");
            }
            printf("\n");
            leaves = leaves + 2;
        }
        branches--;
    }

    // For stand
    for (int i = 1; i &lt;= 2; i++) {
        for (int j = 1; j &lt;= max_leaves / 2; j++) {
            printf(" ");
        }
        printf("*\n");
    }

    return 0;
}


By the way, your text editor should provide some automatic format feature. I formatted the code with clang-format -style="{BasedoNStyle: llvm, IndentWidth: 4}", since that's very similar to your variant.

Don't repeat yourself

Now that we have easy to read code, we can see that there are repeating patterns, namely

for(int k = init; k &lt;= stop; k++) {
    printf("some string");
}


We have at least five occurrences. So let's write a small function:

void repeat_string(int times, const char* str) {
    for(int i = 0; i &lt; times; ++i) {
        printf("%s",str);
    }
}


Let's replace all occurrences of your loop with the function:

#include &lt;stdio.h&gt;

void repeat_string(int times, const char* str) {
    for(int i = 0; i &lt; times; ++i) {
        printf("%s",str);
    }
}

int main() {
    int day;
    scanf("%d", &amp;day);

    // Check for exceptions
    if (day &lt;= 1) {
        printf("You cannot generate christmas tree");
        return 0;
    } else if (day &gt; 20) {
        printf("Tree is no more");
        return 0;
    }

    // printf("Heres Your Christmas Tree:\n\n");

    // For first part
    int leaves = 1;
    int branches = day + 1;
    int max_leaves = 1 + (branches - 1) * 2; // Arithmetic Progression

    for (int i = 1; i &lt;= branches; i++) {
        repeat_string(max_leaves / 2 - i, " ");
        repeat_string(leaves, "*");
        printf("\n");
        leaves = leaves + 2;
    }

    // For remaining parts
    branches = branches - 2;
    for (int rest = 1; rest &lt;= day - 2; rest++) {
        leaves = 3;
        for (int i = 2; i &lt;= branches + 1; i++) {
            repeat_string(max_leaves / 2 - i, " ");
            repeat_string(leaves, "*");
            printf("\n");
            leaves = leaves + 2;
        }
        branches--;
    }

    // For stand
    for (int i = 1; i &lt;= 2; i++) {
        repeat_string(max_leaves / 2; " ");
        printf("*\n");
    }

    return 0;
}


Again, it's easier too read. Also, any optimization we find for repeat_string will now help at all five call sites. Great.

Exercises:


Write repeat_character(int n, char c), which prints a single character c a total of n times.
If we look closely, we can see that the branches look very similar:

for (int i = 1; i &lt;= branches; i++) {           // &lt;---
    repeat_string(max_leaves / 2 - i, " ");     // &lt;---
    repeat_string(leaves, "*");                 // &lt;---
    printf("\n");                               // &lt;---
    leaves = leaves + 2;                        // &lt;---
}

// For remaining parts
branches = branches - 2;
for (int rest = 1; rest &lt;= day - 2; rest++) {
    leaves = 3;                                 
    for (int i = 2; i &lt;= branches + 1; i++) {   // &lt;---
        repeat_string(max_leaves / 2 - i, " "); // &lt;---
        repeat_string(leaves, "*");             // &lt;---
        printf("\n");                           // &lt;---
        leaves = leaves + 2;                    // &lt;---
    }
    branches--;
}


Write a function that draws a single part, e.g. a trapezoid or pyramid width a given width, height, and so on.


Mark read-only values and locations with const

We denoted the str as const char* in order to make sure that we don't accidentally change string's contents. In the same spirit, we can add const to max_leaves:

…
const int max_leaves = 1 + (branches - 1) * 2; // Arithmetic Progression
…


Now typos like max_leaves /= 2 will get cought by the compiler.

Use 0…(n-1) as range, not 1…n

Your ranges use start = 1; i &lt;= end; start++. Since we often work with arrays in C++ and arrays start with 0, it's more common to work with start = 0; start &lt; end; start++. Keep that in mind for future code.

Other remarks

You mix leaves, branches and max_leaves, but their exact meanings are lost for the unprepared reader. Some additional comments can be helpful.

Other than that, the missing whitespace and therefore code structuring was my biggest criticism, but that's a minor point that can get fixed quickly.

Here's the complete code:

#include &lt;stdio.h&gt;

void repeat_string(int times, const char *str) {
    for (int i = 0; i &lt; times; i++) {
        printf("%s", str);
    }
}

void repeat_character(int times, char c) {
    // Exercise 1
}

void draw_part(int height, int start_width, int max_width) {
    // Exercise 2
}

int main() {
    int day;
    scanf("%d", &amp;day);

    // Check for exceptions
    if (day &lt;= 1) {
        printf("You cannot generate christmas tree");
        return 0;
    } else if (day &gt; 20) {
        printf("Tree is no more");
        return 0;
    }

    // printf("Heres Your Christmas Tree:\n\n");

    // For first part
    int branches = day + 1;
    const int max_leaves = 1 + (branches - 1) * 2; // Arithmetic Progression

    // For first part
    draw_part(branches, 1, max_leaves);

    // For remaining parts
    branches -= 2;
    for (int rest = 0; rest &lt; day - 2; rest++) {
        draw_part(branches, 3, max_width);
        branches--;
    }

    // For stand
    for (int i = 0; i &lt; 2; i++) {
        repeat_string(max_leaves / 2; " ");
        printf("*\n");
    }

    return 0;
}