0
566views
Write programs to print following for N lines.

enter image description here

enter image description here

Subject : Structured Programming Approach

Title : Control Structures

Difficulty : Medium

1 Answer
0
0views

1) Program:

#include<stdio.h>

#include<conio.h>

void main()

{

    int i,j;

    clrscr();

    for(i=1;i<=5;i++)

    {

        for(j=5;j>=1;j--)

        {

            if(i==j)

            printf("*");

            else

            printf("%d",j);

        }

        printf("\n");   

    }

    getch();

}

Output:

enter image description here

2) Program:

#include<stdio.h>

#include<conio.h>

void main()

{

    int i,j;

    clrscr();

    for(i=5;i>=1;i--)
    {

        for(j=1;j<i;j++)

        printf(" ");

        for(j=5;j>=i;j--)

        printf("%d",j);

        printf("\n");

    }

    getch();

}

Output:

enter image description here

Please log in to add an answer.