Digital जीवन

Free Online Education for India...

Full width home advertisement

Computer Basic

C Programming

Engineering Graphics

Post Page Advertisement [Top]

Dr. A.P.J. Abdul Kalam Technical University, Lucknow

KCS151 / KCS251 Programming for Problem Solving - Using C Language


Lab Exercises


13. Write a program to draw the following figure:
3 2 1
2 1
1

  *
 **
***


/*
 File: Prgrm13.c
 Author: Aditya Saini
 Date: Jan 16, 2021
 Description: Program to draw the following figure:
 3 2 1
 2 1
 1

   *
  **
 ***
*/

#include <stdio.h>

int main (void)
{
     int i, j;

     for (i = 0; i <= 2; i++)
     {
          for (j = 3 - i; j >= 1; j--)
               printf ("%d ", j);

          printf ("\n");
     }

     printf ("\n\n");

     for (i = 0; i <= 2; i++)
     {
          for (j = 2 - i; j >= 1; j--)
               printf (" ");

          for (j = 0; j <= i; j++)
               printf ("*");

          printf ("\n");
     }

     return 0;
};

Output

3 2 1
2 1
1

  *
 **
***



No comments:

Post a Comment

Please do not post spam links.

Bottom Ad [Post Page]

| Designed by Colorlib