Search This Blog
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
Featured
- Get link
- X
- Other Apps
C Triangle Pattern Programs 3: 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 k = num; k >= i; k--)
{
printf(" ");
}
for(int j = 1; j <= i; j++)
{
printf("%d ", k++);
}
printf("\n");
}
return 0;
}
k is declared twice (once globally and once inside the loop). The outer k is used for printing numbers, while the inner k is used for spacing.
Enter the number:
5
0
1 2
3 4 5
6 7 8 9
10 11 12 13 14
π Explanation
This program prints a continuous number triangle pattern using nested loops. The first inner loop prints spaces for alignment. The variable k starts from 0 and increments after every number is printed, resulting in a sequence of continuous numbers throughout the triangle.
⏱ Time Complexity
O(n²) because nested loops are used to print spaces and numbers.
π Keywords
Continuous Number Triangle Pattern in C, Floyd's Triangle in C, Number Pattern Program, Nested Loop Programs, C Programming Patterns, Triangle Pattern Using Numbers, Incrementing Number Pattern
π· Hashtags
#CProgramming #PatternProgram #NumberPattern #FloydsTriangle #Coding #LearnC #1printf
π’ 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 = num; i >= 1; i--)
{
for(int k = 1; k <= i; k++)
{
printf(" ");
}
for(int j = num; j >= i; j--)
{
printf("%d ", i);
}
printf("\n");
}
return 0;
}
Enter the number:
5
5
4 4
3 3 3
2 2 2 2
1 1 1 1 1
π Explanation
This program prints a repeated number triangle pattern using nested loops. The first inner loop prints spaces for alignment, while the second inner loop prints the current row number repeatedly. As the value of i decreases, the triangle grows wider and displays the same number multiple times in each row.
⏱ Time Complexity
O(n²) because nested loops are used to print spaces and numbers.
π Keywords
Repeated Number Triangle Pattern in C, Number Pattern Program, Triangle Pattern Using Numbers, Nested Loop Programs in C, C Programming Pattern Examples, Number Pyramid Pattern
π· Hashtags
#CProgramming #PatternProgram #NumberPattern #TrianglePattern #Coding #LearnC #1printf
π’ C Program to Print Increasing Number 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 k = 1; k <= i; k++)
{
printf(" ");
}
for(int j = num; j >= i; j--)
{
printf("%d ", j);
}
printf("\n");
}
return 0;
}
Enter the number:
5
5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
π Explanation
This program prints an increasing number triangle pattern using nested loops. The first inner loop prints spaces for alignment, while the second inner loop prints numbers starting from the current row value up to the entered number. As the rows increase, more numbers are displayed, forming a triangle pattern.
⏱ Time Complexity
O(n²) because nested loops are used to print spaces and numbers.
π Keywords
Number Triangle Pattern in C, Increasing Number Pattern, Nested Loop Programs in C, Number Pyramid Pattern, C Programming Pattern Examples, Triangle Pattern Using Numbers
π· Hashtags
#CProgramming #PatternProgram #NumberPattern #TrianglePattern #Coding #LearnC #1printf
π€ 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 k = num; k >= i; k--)
{
printf(" ");
}
for(int j = 1; j <= i; j++)
{
printf("%c ", i + 64);
}
printf("\n");
}
return 0;
}
Enter the number:
5
A
B B
C C C
D D D D
E E E E E
π Explanation
This program prints a repeated alphabet triangle pattern using nested loops. The first inner loop prints spaces to align the triangle, while the second inner loop prints the same alphabet multiple times in each row. The expression i + 64 converts the row number into its corresponding uppercase alphabet using ASCII values (1=A, 2=B, 3=C, and so on).
⏱ Time Complexity
O(n²) because nested loops are used to print spaces and alphabet characters.
π Keywords
Repeated Alphabet Triangle Pattern in C, Character Pattern Program in C, ASCII Alphabet Pattern, Letter Triangle Pattern, Nested Loop Programs in C, C Programming Pattern Examples
π· Hashtags
#CProgramming #PatternProgram #AlphabetPattern #CharacterPattern #Coding #LearnC #1printf
π€ 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 k = num; k >= i; k--)
{
printf(" ");
}
for(int j = 1; j <= i; j++)
{
printf("%c ", j + 64);
}
printf("\n");
}
return 0;
}
Enter the number:
5
A
A B
A B C
A B C D
A B C D E
π Explanation
This program prints an alphabet triangle pattern using nested loops. The first inner loop prints spaces for alignment, while the second inner loop prints alphabets in ascending order. The expression j + 64 converts numbers into uppercase letters using ASCII values, where 1=A, 2=B, 3=C, and so on.
⏱ Time Complexity
O(n²) because nested loops are used to print spaces and alphabet characters.
π Keywords
Alphabet Triangle Pattern in C, Character Pattern Program, ASCII Alphabet Pattern, C Programming Pattern Examples, Letter Triangle Pattern, Nested Loop Programs in C, Alphabet Pyramid Pattern
π· Hashtags
#CProgramming #PatternProgram #AlphabetPattern #CharacterPattern #Coding #LearnC #1printf
⭐ C Program to Print Star 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 k = num; k >= i; k--)
{
printf(" ");
}
for(int j = 1; j <= i; j++)
{
printf("* ");
}
printf("\n");
}
return 0;
}
Enter the number:
5
*
* *
* * *
* * * *
* * * * *
π Explanation
This program prints a right-angled star triangle pattern using nested loops. The first inner loop prints spaces to align the triangle, while the second inner loop prints stars (*) according to the current row number. Each row contains one more star than the previous row.
⏱ Time Complexity
O(n²) because nested loops are used to print spaces and stars.
π Keywords
Star Triangle Pattern in C, Pyramid Pattern in C, Star Pattern Program, Nested Loop Pattern Programs, Triangle Pattern Using Stars, C Programming Pattern Examples
π· Hashtags
#CProgramming #PatternProgram #StarPattern #PyramidPattern #Coding #LearnC #1printf
π€ 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 = num; i >= 1; i--)
{
for(int k = 1; k <= i; k++)
{
printf(" ");
}
for(int j = num; j >= i; j--)
{
printf("%c ", i + 64);
}
printf("\n");
}
return 0;
}
Enter the number:
5
A
B B
C C C
D D D D
E E E E E
π Explanation
This program prints a repeated alphabet triangle pattern using nested loops. The first inner loop prints spaces for proper alignment, while the second inner loop prints the same alphabet repeatedly in each row. The expression i + 64 converts the row number into its corresponding uppercase alphabet using ASCII values (1=A, 2=B, 3=C, etc.).
⏱ Time Complexity
O(n²) because nested loops are used to print spaces and characters.
π Keywords
Repeated Alphabet Triangle Pattern in C, Character Pattern Program in C, ASCII Character Pattern, Alphabet Triangle Using Nested Loops, C Pattern Programs, Letter Pattern in C Programming
π· Hashtags
#CProgramming #PatternProgram #AlphabetPattern #CharacterPattern #Coding #LearnC #1printf
π€ 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 = num; i >= 1; i--)
{
for(int k = 1; k <= i; k++)
{
printf(" ");
}
for(int j = num; j >= i; j--)
{
printf("%c ", j + 64);
}
printf("\n");
}
return 0;
}
Enter the number:
5
E
E D
E D C
E D C B
E D C B A
π Explanation
This program prints an alphabet triangle pattern using nested loops. The first inner loop prints spaces to align the pattern. The second inner loop prints characters by converting numbers to uppercase letters using j + 64, where 1 = A, 2 = B, 3 = C, and so on.
⏱ Time Complexity
O(n²) because nested loops are used to print spaces and alphabet characters.
π Keywords
Alphabet Triangle Pattern in C, Character Pattern Program in C, C Alphabet Patterns, Nested Loop Pattern Programs, ASCII Character Pattern, Triangle Pattern Using Alphabets
π· Hashtags
#CProgramming #PatternProgram #AlphabetPattern #CharacterPattern #Coding #LearnC #1printf
π’ C Program to Print Alternate 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 k = num; k >= i; k--)
{
printf(" ");
}
for(int j = 1; j <= i; j++)
{
printf("%d ", i % 2);
}
printf("\n");
}
return 0;
}
Enter the number:
5
1
0 0
1 1 1
0 0 0 0
1 1 1 1 1
π Explanation
This program prints an alternate binary triangle pattern using nested loops. The first inner loop prints spaces to align the triangle, while the second inner loop prints either 1 or 0 based on the current row number using i % 2. Odd rows print 1s and even rows print 0s.
⏱ Time Complexity
O(n²) because nested loops are used to print spaces and binary values.
π Keywords
Alternate Binary Triangle Pattern in C, Binary Pattern Program in C, 0 and 1 Triangle Pattern, C Pattern Programs, Nested Loop Programs, Odd Even Row Pattern in C
π· Hashtags
#CProgramming #PatternProgram #BinaryPattern #NumberPattern #Coding #LearnC #1printf
π’ 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 k = num; k >= i; k--)
{
printf(" ");
}
for(int j = 1; j <= i; j++)
{
printf("%d ", j % 2);
}
printf("\n");
}
return 0;
}
Enter the number:
5
1
1 0
1 0 1
1 0 1 0
1 0 1 0 1
π Explanation
This program prints a binary triangle pattern using nested loops. The first inner loop prints spaces for proper alignment, while the second inner loop prints alternating 1s and 0s using the expression j % 2. When j is odd, 1 is printed; when j is even, 0 is printed.
⏱ Time Complexity
O(n²) because nested loops are used to print spaces and binary numbers.
π Keywords
Binary Triangle Pattern in C, 0 and 1 Pattern Program in C, C Pattern Programs, Number Triangle Pattern, Nested Loop Programs in C, Binary Pattern Using Modulus Operator
π· Hashtags
#CProgramming #PatternProgram #BinaryPattern #NumberPattern #Coding #LearnC #1printf
π’ C Program to Print 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 k = num; k >= i; k--)
{
printf(" ");
}
for(int j = 1; j <= i; j++)
{
printf("%d ", i);
}
printf("\n");
}
return 0;
}
Enter the number:
5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
π Explanation
This program prints a number triangle pattern. The outer loop controls the rows, the first inner loop prints spaces for alignment, and the second inner loop prints the row number repeatedly according to the current row count.
⏱ Time Complexity
O(n²) because nested loops are used to print spaces and numbers.
π Keywords
C Number Triangle Pattern, Number Pattern in C, Pyramid Pattern in C, C Programming Pattern Programs, Repeating Number Triangle, C Pattern Examples
π· Hashtags
#CProgramming #PatternProgram #NumberPattern #Programming #LearnC #Coding #1printf
πΊ C Program to Print Right-Aligned Number Triangle Pattern
#include <stdio.h>
int main( )
{
int num;
scanf("%d", &num);
for(int i = 1; i <= num; i++)
{
for(int k = num; k >= i; k--)
{
printf(" ");
}
for(int j = 1; j <= i; j++)
{
printf("%d ", j);
}
printf("\n");
}
}
π Explanation:
This program prints a right-aligned triangle of increasing numbers. Spaces are printed first, followed by numbers from 1 to i on each line.
π‘ Sample Output (for input 5):
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
π Keywords:
C pattern programs, triangle pattern in C, right aligned triangle, beginner C exercises
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment