Skip to content

JadeadrinaG8s/Program-2B

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Program-2B

C module 2 EX NO-2)b)a C program to print hollow number pattern series using for loop DATE:19/10/25 NAME:JADE ADRINA J REF NO:25017000 AIM:TO Write a C program to print hollow number pattern series using for loop. ALGORITHM:1)take range as input from the user.2)run through the rows and columns using i and j in for loop.3)using if condition to get the pattern.4)print the pattern using printf() function. PROGRAM:

#include <stdio.h>

int main() {
    int n, i, j;
    scanf("%d", &n);
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= n; j++) {
            if (i == 1) {
                // First row
                printf("%d", j);
            } else if (i == n) {
                // Last row
                printf("%d", n - j + 1);
            } else if (j == 1) {
                // First number in middle rows
                printf("%d", i);
            } else if (j == n) {
                // Last number in middle rows
                printf("%d", n - i + 1);
            } else {
                // Spaces inside hollow part
                printf(" ");
            }
        }
        printf("\n");
    }

    return 0;
}

OUTPUT: Screenshot 2025-10-19 201224 RESULT: thus,a C program to print hollow number pattern series using for loop has been successfully executed.

About

C module 2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published