Numbers and Asterisks - V Pattern

The program must accept an integer N as the input. The program must print the desired pattern as shown in the Example Input/Output section.
Boundary Condition(s):
2 <= N <= 100
Input Format:
The first line contains the value of N.
Output Format:
The lines containing the desired pattern as shown in the Example Input/Output section.
Example Input/Output 1:
Input:
3
Output:
1*2*3
*1*2*
**1**
Example Input/Output 2:
Input:
6
Output:
1*2*3*4*5*6
*1*2*3*4*5*
**1*2*3*4**
***1*2*3***
****1*2****
*****1*****

Solution :-

#include<stdio.h>
#include <stdlib.h>

int main()
{
    int n;
    scanf("%d",&n);
    int x=n;
    
    int len=n+(n-1);
    
    for(int i=1;i<=n;i++)
    {
        for(int x=1;x<i;x++)
        {
            printf("*");
        }
        for(int j=1;j<=n+1-i;j++)
        {
            if(j==x)
            printf("%d",j);
            else
            printf("%d*",j);
        }
        
        for(int x=1;x<i;x++)
        {
            printf("*");
        }
        x--;
        printf("\n");
        
    }
    
    


}

Comments

Popular posts from this blog

Two Matrix Spiral Print

Alphabets Positions Reversed

Odd Factors - (Error Identification) skillrack program id - 7306