Skip to main content

Featured

Merge Sort in C++

  Merge Sort in C++ Introduction Merge Sort is a popular sorting algorithm that follows the Divide and Conquer approach. It divides an array into smaller subarrays, recursively sorts those subarrays, and finally merges the sorted subarrays to produce a completely sorted array. In this tutorial, we will learn how to implement Merge Sort in C++ . The program divides the array into two halves using the mid index, recursively sorts both halves, and then combines them using the merge() function. Merge Sort has a time complexity of O(n log n) in the best, average, and worst cases. Table of Contents Algorithm C++ Program Input Sample Output Output Explanation Dry Run Flow of Execution Time Complexity Space Complexity Applications Key Points Interview Questions Frequently Asked Questions Keywords Conclusion Algorithm Start the program. Read the size of the array. Read the array elements from the user. Call the mer...

C Triangle Pattern Programs 4: Star, Number, Alphabet & Binary Patterns with Output

Pattern Name

Left-Aligned Right-Angled Triangle Star Pattern 

Other acceptable names:

  • Increasing Star Triangle Pattern

  • Left-Aligned Triangle Pattern

  • Right-Angled Star Triangle

  • Half Pyramid Pattern using Stars

This is one of the most classic patterns for beginners in C programming









๐Ÿ”ท Left-Aligned Continuous Number Triangle Pattern

#include <stdio.h>

int main( )
{
    int num, k = 0;

    printf("Enter the number:\n");
    scanf("%d", &num);

    for(int i = 1; i <= num; i++)
    {
        for(int j = 1; j <= i; j++)
        {
            printf("%d ", k++);
        }

        printf("\n");
    }

    return 0;
}










๐Ÿ”ท Triangle Binary Number Pattern

#include <stdio.h>

int main( )
{
    int num, k = 0;

    printf("Enter the number:\n");
    scanf("%d", &num);

    for(int i = 1; i <= num; i++)
    {
        for(int j = 1; j <= i; j++)
        {
            printf("%d ", j % 2);
        }

        printf("\n");
    }

    return 0;
}



*********************************************** 
 

*

* *

* * *

* * * *

* * * * *

#include<stdio.h>

int main( )

{

int num,i,j;

printf("Enter the number:\n");

scanf("%d",&num);

for(i=1;i<=num;i++)

{

        for(j=1;j<=i;j++)

        {

                printf("* ");

        }

        printf("\n");

}

}

***********************************************  

1

2 2

3 3 3

4 4 4 4

5 5 5 5 5

#include<stdio.h>

int main( )

{

int num,i,j;

printf("Enter the number:\n");

scanf("%d",&num);

for(i=1;i<=num;i++)

{

        for(j=1;j<=i;j++)

        {

                printf("%d ",i);

        }

        printf("\n");

}

}

***********************************************  

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

#include<stdio.h>

int main( )

{

int num,i,j;

printf("Enter the number:\n");

scanf("%d",&num);

for(i=1;i<=num;i++)

{

        for(j=1;j<=i;j++)

        {

                printf("%d ",j);

        }

        printf("\n");

}

}

***********************************************  

A

B B

C C C

D D D D

E E E E E

#include<stdio.h>

int main( )

{

int num,i,j;

printf("Enter the number:\n");

scanf("%d",&num);

for(i=1;i<=num;i++)

{

        for(j=1;j<=i;j++)

        {

                printf("%c ",i+64);

        }

        printf("\n");

}

}
***********************************************  

A

A B

A B C

A B C D

A B C D E


#include<stdio.h>

int main( )

{

int num,i,j;

printf("Enter the number:\n");

scanf("%d",&num);

for(i=1;i<=num;i++)

{

        for(j=1;j<=i;j++)

        {

                printf("%c ",j+64);

        }

        printf("\n");

}

}

***********************************************  

5
4 4
3 3 3
2 2 2 2
1 1 1 1 1
#include<stdio.h>
int main( )
{
int num,i,j;
printf("Enter the number:\n");
scanf("%d",&num);
for(i=num;i>=1;i--)
{
        for(j=num;j>=i;j--)
        {
                printf("%d ",i);
        }
        printf("\n");

}
}




Comments

Popular Posts

๐ŸŒ™