Basic

Switch Case

Goto

Operators

if Statement

Nested if

While Loop

For Loop

Array

Patterns

Excersises


Print Square Border Pattern Using For Loop In C Program


Program to print square border pattern of n rows using for loop.

Example : pgm.c

#include<stdio.h>
int main(){
    int i,j,n;
	printf("\n Enter the limit:");
	scanf("%d",&n);
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            if(i==1||i==n||j==1||j==n){
                printf("* ");
            }else{
                printf("  ");
            }
        }
        printf("\n");
    }
    return 0;
}

Output:

Enter the limit: 10
    * * * * * * * * * *
    *                 *
    *                 *
    *                 *
    *                 *
    *                 *
    *                 *
    *                 *
    *                 *
    * * * * * * * * * *