Friday, March 17, 2023

C Programming. Program to print star pattern.

 Program to print star pattern.

// Program to print star triangle.(take number of lines from user).
/*        *
         ***  
        *****
       *******
*/

#include<stdio.h>

int main() {
    int n, i, j;
    printf("Enter number of lines : ");
    scanf("%d", &n);
    for (i=1; i<=n; i++) {
        for (j=1; j<=n-i; j++){
            printf(" ");
        }
        for (j=1; j<=2*i-1; j++){
            printf("*");
        }
        printf("\n");
    }
    return 0;
}

Output :

Enter number of lines : 7 * *** ***** ******* ********* *********** *************

No comments:

Post a Comment

Selection Sort Using C programming.

Selection sort is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or largest) element from the un...