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
Diamond pattern in C:Star, Number, Alphabet & Binary Patterns with Output
⭐ C Program to Print Number Diamond Pattern Using Row Number
#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");
}
for(int i=num;i>=1;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
5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
π Explanation
This program prints a number diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern. The second inner loop prints the current row number repeatedly using i. As the row number increases, the same number is printed multiple times, creating a symmetric diamond-shaped number pattern.
π§ Algorithm
- Read the number from the user.
- Print the upper half of the number diamond.
- Print leading spaces for proper alignment.
- Print the current row number repeatedly in each row.
- Print the lower half of the diamond using another outer loop.
- Repeat until the complete number diamond pattern is displayed.
⏱ Time Complexity
O(n²)
πΎ Space Complexity
O(1)
π Search Description
Learn how to print a number diamond pattern in C using nested loops. This C program prints the current row number repeatedly to create a diamond-shaped number pattern, making it ideal for beginners learning C pattern programs.
π Keywords
number diamond pattern in C, number pattern using row number, C pattern program, repeated number pattern, nested loop pattern in C, diamond pattern using numbers, C programming examples, pattern printing in C.
π· Hashtags
#CProgramming #PatternPrograms #NumberPattern #DiamondPattern #Coding #Programming #NestedLoops #CLanguage #1printf
⭐ C Program to Print Number Diamond Pattern Using Nested Loops
#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);
}
printf("\n");
}
for(int i=num;i>=1;i--)
{
for(int k=num;k>=i;k--)
{
printf(" ");
}
for(int j=1;j<=i;j++)
{
printf("%d ",j);
}
printf("\n");
}
return 0;
}
Enter the number:
5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
π Explanation
This program prints a number diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern correctly, and the second inner loop prints numbers starting from 1 up to the current row number. Together, these loops form a symmetric diamond-shaped number pattern.
π§ Algorithm
- Read the number from the user.
- Print the upper half of the number diamond.
- Print leading spaces for alignment.
- Print numbers from 1 to the current row.
- Print the lower half of the diamond using another outer loop.
- Repeat until the complete number diamond pattern is displayed.
⏱ Time Complexity
O(n²)
πΎ Space Complexity
O(1)
π Search Description
Learn how to print a number diamond pattern in C using nested loops. This beginner-friendly C program demonstrates how to print increasing numbers in a diamond shape using simple loop logic.
π Keywords
number diamond pattern in C, C number pattern program, diamond pattern using numbers, nested loop pattern in C, number pattern examples, C programming patterns, pattern printing in C, C programming tutorial.
π· Hashtags
#CProgramming #PatternPrograms #NumberPattern #DiamondPattern #Coding #Programming #NestedLoops #CLanguage #1printf
⭐ C Program to Print Star Diamond Pattern Using Nested Loops
#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");
}
for(int i=num;i>=1;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 star diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern correctly, and the second inner loop prints stars (*) in each row. Together, these loops create a complete diamond-shaped star pattern.
π§ Algorithm
- Read the number from the user.
- Print the upper half of the star diamond.
- Print leading spaces for proper alignment.
- Print stars using the second inner loop.
- Print the lower half of the diamond using another outer loop.
- Repeat until the complete star diamond pattern is displayed.
⏱ Time Complexity
O(n²)
πΎ Space Complexity
O(1)
π Search Description
Learn how to print a star diamond pattern in C using nested loops. This beginner-friendly C program demonstrates how to combine loops and spaces to create a diamond-shaped pattern using asterisks (*).
π Keywords
star diamond pattern in C, diamond pattern using stars, C star pattern program, nested loop pattern in C, star pattern using loops, C pattern printing examples, diamond shape pattern, C programming tutorial.
π· Hashtags
#CProgramming #PatternPrograms #StarPattern #DiamondPattern #Coding #Programming #NestedLoops #CLanguage #1printf
⭐ C Program to Print Alphabet Diamond Pattern Using Row Number
#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");
}
for(int i=num;i>=1;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
E E E E E
D D D D
C C C
B B
A
π Explanation
This program prints an alphabet diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern. The second inner loop prints the same alphabet repeatedly in each row using the expression i + 64. Since the ASCII value of A is 65, each row displays its corresponding alphabet multiple times.
π§ Algorithm
- Read the number from the user.
- Print the upper half of the alphabet diamond.
- Print leading spaces to align the pattern.
- Print the same alphabet repeatedly in each row using i + 64.
- Print the lower half of the diamond using another outer loop.
- Repeat until the complete alphabet diamond pattern is displayed.
⏱ Time Complexity
O(n²)
πΎ Space Complexity
O(1)
π Search Description
Learn how to print an alphabet diamond pattern in C using nested loops. This C program uses the row number and ASCII values to print the same uppercase letter repeatedly in each row, making it an excellent example for beginners learning pattern programs.
π Keywords
alphabet diamond pattern in C, alphabet pattern using row number, ASCII character pattern, C pattern programs, diamond pattern using alphabets, nested loop pattern in C, C programming examples, pattern printing in C.
π· Hashtags
#CProgramming #PatternPrograms #AlphabetPattern #DiamondPattern #Coding #Programming #NestedLoops #CLanguage #1printf
⭐ C Program to Print Alphabet Diamond Pattern Using Nested Loops
#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");
}
for(int i=num;i>=1;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
A B C D E
A B C D
A B C
A B
A
π Explanation
This program prints an alphabet diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern. The second inner loop prints uppercase alphabets starting from A using the expression j + 64, where the ASCII value of A is 65.
π§ Algorithm
- Read the number from the user.
- Print the upper half of the alphabet diamond.
- Print leading spaces for proper alignment.
- Print alphabets from A onward using j + 64.
- Print the lower half of the diamond using another outer loop.
- Repeat until the complete alphabet diamond pattern is displayed.
⏱ Time Complexity
O(n²)
πΎ Space Complexity
O(1)
π Search Description
Learn how to print an alphabet diamond pattern in C using nested loops. This beginner-friendly C program demonstrates pattern printing with uppercase letters using ASCII values.
π Keywords
alphabet diamond pattern in C, C alphabet pattern, character pattern program, ASCII pattern in C, diamond pattern using alphabets, nested loop pattern, C programming examples, pattern printing in C.
π· Hashtags
#CProgramming #PatternPrograms #AlphabetPattern #DiamondPattern #Coding #Programming #NestedLoops #CLanguage #1printf
⭐ C Program to Print Binary Diamond Pattern Using Row Number
#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");
}
for(int i=num;i>=1;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
1 1 1 1 1
0 0 0 0
1 1 1
0 0
1
π Explanation
This program prints a binary diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern. The second inner loop prints either 0 or 1 based on the current row number using the expression i%2. Odd-numbered rows print 1s, while even-numbered rows print 0s, forming a binary diamond pattern.
π§ Algorithm
- Read the number from the user.
- Print the upper half of the binary diamond.
- Print leading spaces for alignment.
- Print the value of i%2 repeatedly in each row.
- Print the lower half of the diamond using another outer loop.
- Repeat until the complete binary diamond pattern is displayed.
⏱ Time Complexity
O(n²)
πΎ Space Complexity
O(1)
π Search Description
Learn how to print a binary diamond pattern in C using nested loops. This program uses the row number and the modulus operator to print alternating rows of 1s and 0s, making it ideal for beginners learning C pattern programs.
π Keywords
C binary diamond pattern, binary diamond using row number, binary pattern in C, pattern printing in C, nested loop pattern program, C pattern examples, modulus operator in C, C programming tutorial.
π· Hashtags
#CProgramming #PatternPrograms #BinaryPattern #DiamondPattern #Coding #Programming #NestedLoops #CLanguage #1printf
⭐ C Program to Print Binary Diamond Pattern Using Nested Loops
#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");
}
for(int i=num;i>=1;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
1 0 1 0 1
1 0 1 0
1 0 1
1 0
1
π Explanation
This program prints a binary diamond pattern using nested loops. The first outer loop prints the upper half of the diamond, while the second outer loop prints the lower half. The first inner loop prints leading spaces to align the pattern. The second inner loop prints alternating binary values using j%2. Since the values depend on the column number, every row begins with 1 and alternates between 1 and 0.
π§ Algorithm
- Read the number from the user.
- Print the upper half of the binary pattern.
- Print leading spaces using the first inner loop.
- Print alternating binary values using j%2.
- Print the lower half using another outer loop.
- Repeat until the complete binary diamond pattern is printed.
⏱ Time Complexity
O(n²)
πΎ Space Complexity
O(1)
π Search Description
Learn how to print a binary diamond pattern in C using nested loops. This program prints alternating 1s and 0s to form a diamond shape and is a great example for beginners learning pattern printing in C.
π Keywords
C binary diamond pattern, binary pattern in C, diamond pattern using loops, C pattern programs, alternating 1 and 0 pattern, nested loop examples, pattern printing in C, C programming examples.
π· Hashtags
#CProgramming #PatternPrograms #BinaryPattern #DiamondPattern #Coding #Programming #NestedLoops #CLanguage #1printf
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