Question

In C programming language: This program will output a right triangle based on user specified height...

In C programming language:

This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar.

(1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt)

(2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as % or *. Each subsequent line will have one additional user-specified character until the number in the triangle's base reaches triangleHeight. Output a space after each user-specified character, including a line's last user-specified character. (2 pts)

Example output for triangleChar = % and triangleHeight = 5:

Enter a character: %
Enter triangle height: 5
% 
% % 
% % % 
% % % % 
% % % % % 

#include <stdio.h>

int main(void) {
char triangleChar = '-';
int triangleHeight = 0;

printf("Enter a character: \n");
scanf("%c", &triangleChar);

printf("Enter triangle height: \n");
scanf("%d", &triangleHeight);

printf("* \n");
printf("* * \n");
printf("* * * \n");

return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main(void) {
    char triangleChar;
    int triangleHeight;

    printf("Enter a character:\n");
    scanf(" %c", &triangleChar);

    printf("Enter triangle height:\n");
    scanf("%d", &triangleHeight);
    printf("\n");

    int i, j;
    for(i = 0; i < triangleHeight; ++i) {
        for(j = 0; j <= i; ++j) {
            printf("%c ", triangleChar);
        }
        printf("\n");
    }
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
In C programming language: This program will output a right triangle based on user specified height...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in Java This program will output a right triangle based on user specified height triangleHeight and...

    in Java This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a character. Modify the given program to output a right triangle that instead uses the user-specified trianglechar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as % or* Each subsequent line will...

  • (In C++) The program will output a right triangle based on user specified height triangleHeight and...

    (In C++) The program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. Modify the program to use a nested loop to output a right triangle of height triangleHeight. The 1st line will have one user-specified character, such as %or * Each subsequent line will have 1 additional user-specified character until the number in the triangle"s base reaches triangleHeight. Output a space after each user-specified character, including after the line"s last user-specified character. Example output...

  • Hello there, im trying to answer this question in c 4.22 LAB: Warm up: Drawing a...

    Hello there, im trying to answer this question in c 4.22 LAB: Warm up: Drawing a right triangle This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height...

  • I need the programming to be in language C. I am using a program called Zybook...

    I need the programming to be in language C. I am using a program called Zybook Prompt: Write a statement that outputs variable numObjects. End with a newline. Given: #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); return 0; } What I did so far. I am not sure if its right tho? #include <stdio.h> int main(void) { int numObjects; scanf("%d", &numObjects); printf(" num Objects is "); printf("%d\n", userAge); return 0; }

  • This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The...

    This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow base height, arrow base width, and arrow head width. (1) Modify the given program to use a loop to output an arrow base of height arrowBaseHeight. (1 pt) (2) Modify the given program to use a loop to output an arrow base of width arrowBaseWidth. Use a nested loop in which the inner loop draws the...

  • Write a C program that does the following: Displays a menu (similar to what you see...

    Write a C program that does the following: Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square,Diamond (with selected height and selected symbol), or Quits if user entered Q.Apart from these 2 other shapes, add a new shape of your choice for any related character. Program then prompts the user to enter a number and...

  • Hello, I need help with the following C code. This program asks the user to enter...

    Hello, I need help with the following C code. This program asks the user to enter three numbers and outputs the sum on the screen , all im trying to do is have the program reprompt the user for a number if anything other than a number is entered for each of the entries. I wanted to use do while for each of the functions but that did not work for example: Enter Number 1: 2 Enter Number 2: Hello...

  • Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the O...

    Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the OpenMP parallel program much longer? Serial Program #include <stdio.h> #include <string.h> #include <time.h> int main(){    char str[1000], ch;    int i, frequency = 0;    clock_t t; struct timespec ts, ts2;       printf("Enter a string: ");    gets(str);    int len = strlen(str);    printf("Enter a character...

  • Write a Python function make_triangle(trianglechar, triangleheight) that will return a string with an isosceles right triangle...

    Write a Python function make_triangle(trianglechar, triangleheight) that will return a string with an isosceles right triangle based on the two formal parameters triangle_height giving the triangle height and triangle_char that gives the symbol to be printed. Important notes: This program returns (not prints!) a string. For this function and the other part of this lab you are required to put in a docstring. That will be checked by a TA/grader reading the program. Every one of the occurrences of triangle_char...

  • I'm having trouble getting my program to print shapes For example: Which shape (L-line, T-triangle, R-rectangle):...

    I'm having trouble getting my program to print shapes For example: Which shape (L-line, T-triangle, R-rectangle): L Enter an integer length between 1 and 25: 13 ************* Which shape (L-line, T-triangle, R-rectangle): t Enter an integer base length between 3 and 25: 5 * ** *** **** ***** Which shape (L-line, T-triangle, R-rectangle): r Enter an integer width and height between 2 and 25: 4 5 **** **** **** **** **** Here's my code: #include <stdio.h> #include <ctype.h> const int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT