Write a program that prints triangle shaped patterns using the numbers 1 through
ID: 3763435 • Letter: W
Question
Write a program that prints triangle shaped patterns using the numbers 1 through 9. The program will ask the user to enter a number in the range 1 through 9 that will be used as the upper bound on the numbers in the pattern. The program will also ask the user to enter the type of pattern they would like to see.
• Pattern A is a triangle with the hypotenuse on the upper right that is composed of rows of increasing numbers. The base is a row of the numbers 1 through the number entered by the user in ascending order from left to right. Each row above the base has one less number than the row below. All rows start with 1. See the sample output provided to see the exact pattern required.
• Pattern B is a triangle with the hypotenuse on the upper right that is composed of rows of decreasing numbers. The base is a row of the numbers beginning with the number entered by the user down through 1 in descending order from left to right. Each row above the base has one less number than the row below. All rows start with the user’s number. See the sample output provided to see the exact pattern required.
• Pattern C is a triangle with the hypotenuse on the upper left that is composed of rows of decreasing numbers. The base is a row of the numbers beginning with the number entered by the user down through 1 in descending order from left to right. Each row above the base has one less number than the row below. All rows end with 1. See the sample output provided to see the exact pattern required.
Your program must be composed of at least (you can have more) four functions: main(), displayPatternA(), displayPatternB(), and displayPatternC(). The functions displayPatternA(), displayPatternB(), and displayPatternC() will be void functions that accept the users number as an argument and perform the task of displaying the required pattern
Explanation / Answer
#include<stdio.h>
void main()
{
int i,j,rows,range=1;
char A,B,C;
printf("enter upper limit range");
scanf("%d",&range);
printf("enter pattern type");
scanf("%c%c%c"&A,&B,&C);
if(pattern=='A');
{
displaypatternA(range);
}
elseif(pattern=='B');
{
displayPatternB(range);
}
elseif(pattern=='C');
{
displayPatternC(range);
}
else
{
printf("no pattern selected");
}
void displayPatternA(int range)
{
printf("enter the no. of rows");
scanf("%d",&rows);
for(i=1;i<=rows;++i)
{
for(j=1;j<=i;++j)
{
printf("%d",&j);
}
printf(" ");
}
void displayPatternB(int range)
{
printf(“enter the no.of rows “);
scanf(“%d”,&rows);
for(i=rows;i>=1;i–-)
{
for(j=i;j>=1;j–-)
printf(“%d “,j);
printf(“ ”);
}
void displayPatternC(int range)
{
printf("enter the no. of rows");
scanf("%d",&rows);
for(i=rows;i>=1;i--)
{
for(j=1;j<=i;++j)
{
printf("%d",j);
}
}
NOTE:In this question any sample pattern is not displayed.According to my understanding i wrote a program to print the pattern.so,Please inform to me if you need other than these patterns.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.