Pattern printing

Output:

Obtain a output as follows: 
N=5 

2*3 
4*5*6 
7*8*9*10 
11*12*13*14*15 
11*12*13*14*15 
7*8*9*10 
4*5*6 
2*3 
1

Program:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
    int n;
    int num=1;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=i;j++)
        {
            printf("%d",num);
            if(j>=0&&j<i)
            {
                printf("*");
            }
            num++;
        }
        printf("\n");
    }
    int j;
    for(int i=n-1;i>=0;i--)
    {
        int val=num-i-1;
        for(j=0;j<=i;j++)
        {
            printf("%d",val);
            if(j<i)
            {
                printf("*");
            }
            val++;
        }
        num=val-j;
        printf("\n");
    }
    return 0;
}

Comments

Popular posts from this blog

C program to print the following Pattern

For any given matrix find the path from the start to the end which gives the maximum sum. Traverse only right or down. Example: starting index is 15 (left top) and ending index is 10 (bottom right) 15 25 30 45 25 60 70 75 10 O/P:15->45->70->75->10 sum is 215

c++ program to print string along the diagonals of the matrix.