Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

CTS & Wipro Automata | No. 11 | 18.09.2021

Pattern Printing Number with Asterisk 

Pattern Printing Number with Asterisk Program in C language

The program must accept an integer N as the input. The program must print the desired pattern as shown in the Example Input/Output sections.

Boundary Condition(s):
1 <= N <= 100

Input Format:
The first line contains the value of N.

Output Format:
The first 2*N lines contain the desired pattern as shown in the Example Input/Output sections.

Example Input/Output 1:
Input:
4

Output:
1
2*3
4*5*6
7*8*9*10
7*8*9*10
4*5*6
2*3
1

Example Input/Output 2:
Input:
7

Output:
1
2*3
4*5*6
7*8*9*10
11*12*13*14*15
16*17*18*19*20*21
22*23*24*25*26*27*28
22*23*24*25*26*27*28
16*17*18*19*20*21
11*12*13*14*15
7*8*9*10
4*5*6
2*3
1

C Program for Pattern Printing Number with Asterisk


#include<stdio.h>
#include <stdlib.h>
int main()
{
    int n,limit=1,var=0;
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++)
    {
        int p=var;
        for(int j=1;j<=limit;j++)
        {
            printf("%d",++p);
            if(j!=limit)
            {
                printf("*");
            }
        }
        if(i<n)
        {
            limit++;
            var=p;
        }
        else if(i>n)
        {
            limit--;
            var=var-limit;
        }
        printf("\n");
    }
    return 0;
}


Inverted Trapezium Pattern Program In C


Inverted Trapezium Pattern Program In C: The program must accept an integer N as the input. The program must print the desired pattern as shown in the Example Input/Output sections.

Boundary Condition(s):
1 <= N <= 100

Input Format:
The first line contains the value of N.

Output Format:
The first N lines contain the desired pattern as shown in the Example Input/Output sections.

Example Input/Output 1:
Input:
4

Output:
– – – 10 11
– – 8 9 12 13
– 5 6 7 14 15 16
1 2 3 4 17 18 19 20

Example Input/Output 2:
Input:
5

Output:
– – – – 15 16
– – – 13 14 17 18
– – 10 11 12 19 20 21
– 6 7 8 9 22 23 24 25
1 2 3 4 5 26 27 28 29 30


C Program

#include <stdio.h>
void print(int n)
{
    while(n-->0)printf("- ");
}
int main()
{
    int n;
    scanf("%d",&n);
    int var= (n*(n+1))/2;
    int p1=var,p2=var+1;
    for(int i=1;i<=n;i++)
    {
        print(n-i);
        for(int j=1;j<=i;j++)
        {
            printf("%d ",p1+j-1);
        }
        p1=p1-(i+1);
        for(int j=1;j<=i;j++)
        {
            printf("%d ",p2++);
        }
        printf("\n");
    }
    return 0;
}



Post a Comment

Previous Post Next Post