Question

Write a program that reads an integer greater or equal to 2, n, and prints a...

Write a program that reads an integer greater or equal to 2, n, and prints a shape of a nline
hollow inverted pyramid of stars.
Your program should interact with the user exactly as it shows in the following two
executions:

Execution example 1:
Please enter an integer, greater or equal to 2:
5
*********
-*----- *
--*--- *
---*--*
----*
Execution example 2:
Please enter an integer, greater or equal to 2:
3
*****
-* *
--*

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++Program:

#include<iostream>

using namespace std;

int main()

{

int i, j, n;

cout<<"Enter number of rows greater than or equal 2: ";

cin>>n;

for(i=1; i<=n; i++)

{

for(j=1;j<i;j++)

{

cout<<" ";

}

for(j=1;j<=(n*2-(2*i-1));j++)

{

if(i==1||j==1||j==(n*2-(2*i - 1)))

{

cout<<"*";

}

else

{

cout<<" ";

}

}

cout<<endl;

}

return 0;

}

if you like the answer please provide a thumbs up.

clang version 7.0.0-3-ubuntu0.18.04.1 (tags/RELEASE_700/final) } clang++-7-pthread -o main main.cpp } ./main Enter number of rows greater than or equal 2: 5

https://Powerless Grounded Variable.kunlstudy.repl.run clang version 7.0.0-3-ubuntu0.18.04.1 (tags/RELEASE 700/final) } clang++-7 pthread -o main main.cpp } ./main Enter number of rows greater than or equal 2: 3

Add a comment
Know the answer?
Add Answer to:
Write a program that reads an integer greater or equal to 2, n, and prints a...
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
  • Write a program that prompts the user for a positive integer, n, and then prints a...

    Write a program that prompts the user for a positive integer, n, and then prints a following shape of stars using nested for loop, System.out.print(“*”);, and System.out.println();. Example1: Enter a positive integer: 3 * * * * * * * * * Example2: Enter a positive integer: 5 * * * * * * * * * * * * * * * * * * * * * * * * * JAVA LANGUAGE!!

  • Write a program that reads a positive integer N, where N is greater than 1 and...

    Write a program that reads a positive integer N, where N is greater than 1 and prints the value of the floating-point value SUM where SUM is the results of the following series. SUM = 1/1! + 2/2! + 3/3! + 4/4! + ... N/N! Note that your program should print the message “Sorry, bad N”” if N is <=1, and keep reading user input until the user enters a valid value for N. Also, note that all division operations...

  • Write the following code in C. Write a program that takes a positive integer and prints...

    Write the following code in C. Write a program that takes a positive integer and prints that many stars These are sample outputs. Enter the number of stars: 9 Enter the number of stars: 4 Enter the number of stars: -3 Invalid input!

  • Write a program file_max.c that reads a set of integer numbers from a file and prints...

    Write a program file_max.c that reads a set of integer numbers from a file and prints out the maximum number to standard output. The name of the input file should be specified as a command line argument.

  • This Java program reads an integer from a keyboard and prints it out with other comments....

    This Java program reads an integer from a keyboard and prints it out with other comments. Modify the comments at the top of the program to reflect your personal information. Submit Assignment1.java for Assignment #1 using Gradescope->Assignemnt1 on canvas.asu.edu site. You will see that the program has a problem with our submission. Your program is tested with 4 testcases (4 sets of input and output files). In order to pass all test cases, your program needs to produce the same...

  • 2. Write a program that reads N integer numbers of array from the user and then...

    2. Write a program that reads N integer numbers of array from the user and then displays the sum, max number and the numbers of the array use four subroutines ( Read_Array(), Calculate_Sum(), Find_Max() and Display_Array()). Here is sample output Please enter number of elements: 4 Please enter the required numbers: 50 100 150 20 The entered numbers are: 50 100 150 20 Sum is : 320 Max is 150 by Mpsi ,sum and max to call subroutine and retrieve...

  • In Python 3 - Write a program that reads a sequence of integer inputs from the...

    In Python 3 - Write a program that reads a sequence of integer inputs from the user. When the user is finished entering the integers, they will enter a 'q'. There is no need to check if the entry is a valid integer. All integers in the test data (input) will be between -255 and 255. The program should then print: The smallest and largest of the inputs. The number of even and odd inputs (0 should be considered even)...

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

  • Write a program “hw4.c” that reads integer (less than or equal 100) from the keyboard and,...

    Write a program “hw4.c” that reads integer (less than or equal 100) from the keyboard and, on the output, writes the sum of the divisors of n (other than itself). For integers less than or equal to 1 it should print 0. For example, the input -3 0 1 4 5 6 12 should generate the output 0 0 0 3 1 6 16 Explanation of output: The input -3 is less than 1, output is 0. The input 0...

  • Write a program which prompts the user to enter a number of rows, and prints a...

    Write a program which prompts the user to enter a number of rows, and prints a hollow square star pattern with 2 diagonals. Note: you can assume that the integer will always be > 1 and will be an odd number. For example: Input Result 5 Enter number of rows: 5 ***** ** ** * * * ** ** ***** 9 Enter number of rows: 9 ** ** ** * * * * * * * * * * **...

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
ADVERTISEMENT