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
C programming 3. Write a do-while loop that displays: 0,10,20,30,40 4.Write nested for loops that displays...
C programming 3. Write a do-while loop that displays: 0,10,20,30,40 4.Write nested for loops that displays three rows of asterisks: ***** ***** ***** 5. Write a complete program that reads a set of integers using scant() until a sentinel value of -99 is read. Once that value is read, display the sum of the value read, exclusive of the -99. 6.Write a procedure(function, method named times10() that accepts an integer argument and displays the result of multiplying the argument by...
Write a java program to display a given range of integer numbers (0 to 9) in...
Write a java program to display a given range of integer numbers (0 to 9) in the following order: Example : given (5 to 9), the program displays 56789 67895 78956 89567 95678 The first line displays the min to max range. Each line that follows should display the next higher number except when it hits the maximum number. In that situation, the line wraps back to the minimum sequence. For this problem write a static method to do the...
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 C program that reads in a float constant (use %f in scanf) and displays...
Write a C program that reads in a float constant (use %f in scanf) and displays its internal representation in hex. Use your program to check your answers to problem 1. Hint: a union is like a struct except that the fields overlap. Hint: the conversion code for hex is %x. union X { int a; float b; }; int main() { union X test; ... ; test.a and test.b refer to same word in memory but have ; different...
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.
1. Write a complete program in C++ that does the following: [2] asks a user to...
1. Write a complete program in C++ that does the following: [2] asks a user to enter two integer numbers (display a warning message that the second number should be different from zero) [3] reads the two numbers from the keyboard; [4] displays the product, the sum, the quotient and the remainder of integer division of the first one by the second one. [3] displays the result of floating-point division. Make sure to follow programming style guidelines.
[JAVA] Write a program that prompts the user for an integer and displays if the provided...
[JAVA] Write a program that prompts the user for an integer and displays if the provided integer is a prime number or not. A prime number is a number that is divisible only by 1 and itself. First few prime numbers are 2,3,5,7,11,13 and so on. [using if-statements, and if-else-statement ]
problem 1 Write a program that asks the user for an integer and then prints out...
problem 1 Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 84, the program should print 2 2 3 7 Validate the input to make sure that it is not a character or a string using do loop. in c plus plus
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
Write a program in C++ that reads integer values from standard input and writes to standard...
Write a program in C++ that reads integer values from standard input and writes to standard output the smallest of the inputs and the average input value. The program should stop reading when a value equal to -1 or greater than 100 is encountered. It should also stop when an incorrect integer value (i.e., anything that isn't an int) is entered. If there is not an integer value in the input, the program should output "no integers provided"
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT