Write a program to print following patterns :

 


 GTU Programming for Problem Solving Practical-29


/*29. Write a program to print following patterns : 
  i.  *
      * *
      * * *
      * * * * 
      * * * * *                                       
*/
#include <stdio.h>
  int  main(void)
{
    for(int i=1; i<=5; i++)
    {
        for(int j=1; j<=i; j++)
        {
            printf("* ");
        }
        printf("\n");
    }
    return 0;
}

Output:


* *
* * *
* * * *
* * * * *

// Patten 2

//     *
//    * *
//   * * *
//  * * * *
// * * * * *

#include <stdio.h>
int main(void)
{
    int i, j, space =5;

    for (i = 0; i <= 5; i++)
    {
        for (j = 1; j <= space; j++)
        {
            printf(" ", space);
        }
        space--;
        for (j = 1; j <= i; j++)
        {
            printf("* ");
        }
        printf("\n");
    }

    return 0;
}

Output:


    *
   * *
  * * *
 * * * *
* * * * *

// Pattern 3
// *****
// ****
// ***
// **
// *

#include <stdio.h>
int main(void)
{
    for (int i = 5; i >= 1; i--)
    {
        for (int j = 1; j <= i; j++)
        {
            printf("* ");
        }
        printf("\n");
    }
    return 0;
}

Output:


* * * * * 
* * * *
* * *
* *
*

Post a Comment

0 Comments