Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! π
πΉLearn advanced coding techniques in C& C++
πΉMaster Linux internals & shell scripting
πΉDeep dive into Data Structures & Algorithms
πΉExplore Embedded Systems & Microcontrollers (8051,UART, RTOS)
πΉGet hands-on coding tutorials, project ideas,and interview preparation tips
Whether you're a beginner or an experienced programmer, this channel will help you
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 2: Star, Number, Alphabet & Binary Patterns with Output
π’ C Program to Print 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=i;j<=num;j++)
{
printf("%d ",k++);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
0 1 2 3 4
5 6 7 8
9 10 11
12 13
14
π’ C Program to Print Repeated Binary Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%d ",i%2);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
1 1 1 1 1
0 0 0 0
1 1 1
0 0
1
π’ C Program to Print Binary Number Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%d ",j%2);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
1 0 1 0 1
0 1 0 1
1 0 1
0 1
1
⭐ C Program to Print Inverted Star Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("* ");
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
* * * * *
* * * *
* * *
* *
*
π€ C Program to Print Reverse Repeated Alphabet Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=num;i>=1;i--)
{
for(int j=i;j>=1;j--)
{
printf("%c ",i+64);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
E E E E E
D D D D
C C C
B B
A
π€ C Program to Print Reverse Alphabet Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=num;i>=1;i--)
{
for(int j=i;j>=1;j--)
{
printf("%c ",j+64);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
E D C B A
D C B A
C B A
B A
A
π€ C Program to Print Repeated Alphabet Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%c ",i+64);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
A A A A A
B B B B
C C C
D D
E
π€ C Program to Print Alphabet Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%c ",j+64);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
A B C D E
B C D E
C D E
D E
E
π’ C Program to Print Repeated Number Triangle Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%d ",i);
}
printf("\n");
}
return 0;
}
π‘ Sample Output (Input: 5)
1 1 1 1 1
2 2 2 2
3 3 3
4 4
5
π’ C Program to Print Descending Number Pattern
#include <stdio.h>
int main()
{
int num;
printf("Enter the number:\n");
scanf("%d",&num);
for(int i=1;i<=num;i++)
{
for(int j=i;j<=num;j++)
{
printf("%d ",j);
}
printf("\n");
}
return 0;
}
π Explanation:
This C program prints a descending number pattern using nested loops.
The outer loop controls the rows, while the inner loop prints numbers
starting from the current row number up to the entered number.
Comments
Post a Comment