Question

Problem 2: Write a program that reads an integer and displays, using asterisks, a filled diamond...

Problem 2: Write a program that reads an integer and displays, using asterisks, a filled diamond of the given side length. For example, if the side length is 5, the program should display c++ look like a diamond

Homework Answers

Answer #1

/*If you any query do comment in the comment section else like the solution*/

#include<iostream>
using namespace std;
int main() {
    int n, i, j, k;
    cout<<"Enter length of diamond: ";
    cin>>n;
    for(i=0;i<n;i++) {
        for(j=i;j<n-1;j++) {
            cout<<" ";
        }
        for(j=0;j<=i;j++) {
            cout<<"* ";
        }
        cout<<endl;
    }
    for(i=n-1;i>=0;i--) {
        for(j=n-1;j>i;j--) {
            cout<<" ";
        }
        for(j=0;j<=i;j++) {
            cout<<"* ";
        }
        cout<<endl;
    }
}

Know the answer?
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
Similar Questions
Using a while loop, write a program that reads 10 integer numbers. The program shall count...
Using a while loop, write a program that reads 10 integer numbers. The program shall count how many of them are multiples of 2, how many are multiples of 3, and how many are NOT multiples of either 2 or 3. The output should be similar to the one shown below. c++ language
Write a program that reads three integer values from the keyboard using the Scanner class representing,...
Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.
given an integer, write a program in C++ that displays the number as follows first line        ...
given an integer, write a program in C++ that displays the number as follows first line         all digits second line   all except first digit ... last line          last digit ex) 5 6 7 8 6 7 8 7 8 8
Challenge 1 - SumDigits.java Write a program that reads an integer between 0 and 1000 and...
Challenge 1 - SumDigits.java Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer. For example, if an integer is 837, the sum of all digits is 18. Sample output: Enter an integer between 0 and 1000: 837 The sum of all digits in 837 is 18
Problem 2 write Pseudocode for a program that calculates and displays a customer's bank balance at...
Problem 2 write Pseudocode for a program that calculates and displays a customer's bank balance at the end of a month. The customer's bank balance at the end of the month is the beginning bank balance + the total amount of monthly deposit made - the total amount of monthly withdrawals made + interest earned. The information the program will need to get from the user is the beginning bank balance, the amount of monthly deposits , the amount of...
using python Write a program that displays all of states in the U.S. and display each...
using python Write a program that displays all of states in the U.S. and display each state that begins with the letter A.
Write a program that reads an integer, a list of words, and a character. The integer...
Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list of words will always contain fewer than 20 words. Ex: If the input is: 4 hello zoo sleep drizzle z then...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will...
In Java. Write a program that reads-in a times table-number. The program, using this table-number will produce the following report (as shown). The first item in the report is a number with starting value 1. Second column is the word “ X ” (representing the times symbol). Third column is the table-number (itself). Following is an equal sign “ = “ (representing a result). Last column is the result of the operation for that line or row which is the...
given an integer, write a program that displays the number as follows first line         all digits...
given an integer, write a program that displays the number as follows first line         all digits second line   all except first digit third line        all except first two digits ..... last line          the last digit ex) 5 6 7 8 6 7 8 7 8 8
In JAVA: Write a program that reads an integer, a list of words, and a character....
In JAVA: Write a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character. Assume that the list of words will always contain fewer than 20 words. Ex: If the input is: 4 hello zoo sleep drizzle...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT