Printing pattern using loops problem solution | C | HackerRank

Input Format
The input will contain a single integer .
Constraints
Output Format
Print the pattern mentioned in the problem statement.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
int main() 
{
    int n;
    scanf("%d", &n);
    int len = n*2 - 1;
    for(int i=0;i<len;i++){
        for(int j=0;j<len;j++){
            int min = i < j ? i : j;
            min = min < len-i ? min : len-i-1;
            min = min < len-j-1 ? min : len-j-1;
            printf("%d ", n-min);
        }
        printf("\n");
    }
    return 0;
}
Click Here TO Run

Comments

Popular posts from this blog

Insertion Sort - Part 2 | C | HACKERRANK

Array Reversal problem solution | C | HackerRank

Insertion Sort - Part 1 | C | HackerRank |