/* Triangle Pattern : Take input from the user and ask user to choose 0 for triangular star pattern and 1 for reverse triangular star pattern. */
#include <stdio.h>
int main()
{
int choice, n, i, j;
printf("Press 0 if u want a triangular star pattern.\nPress 1 if u want a reverse tiangular star pattern.\n");
scanf("%d", &choice);
switch (choice)
{
case 0:
printf("Enter the number of rows wanted in star pattern: ");
scanf("%d", &n);
for(i = 1; i <= n; i++){
for(j = 1; j <= i; j++){
printf("* ");
}
printf("\n");
}
break;
case 1:
printf("Enter the number of rows wanted in star pattern: ");
scanf("%d", &n);
for(i = n; i >= 1; i--){
for(j = i; j >= 1; j--){
printf("* ");
}
printf("\n");
}
default:
printf("\nPlease enter a valid choice.....");
break;
}
return 0;
}
Comments
Post a Comment