Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #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 <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

C Program to Print Right-Aligned Triangle Number Pattern

πŸ”Ί 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

Comments

Popular Posts

πŸŒ™