I'm trying to create a C program that prints a triangular pattern according to height by only using 1, 2 and 3 to generate the patterns:
Enter the height:
7
Pattern:
1
22
333
1111
22222
333333
1111111
I am only able to print the numbers but I do not know how to print only using 1, 2 and 3
This is my code so far:
printf("Enter the height: \n");
scanf("%d", &height);
if(height <0 || height > 10){
printf("Please enter height within 1 to 10!");
}
else{
printf("Pattern: \n");
for(row=1; row<=height; row++){
for(int col=1; col<=row; col++){
printf("%d", row );
}
printf("\n");
}
return 0;
}
The output:
Enter the height:
7
Pattern:
1
22
333
4444
55555
666666
7777777
Thank you
%) is your friend here.