Example: Rhombus of Stars

Write a program, which takes a positive integer n and prints a rhombus of stars with size n.

Input Output Input Output
1 * 2  * 
* *
 * 
Input Output Input Output
3   *  
 * * 
* * *
 * * 
  *  
4    *   
  * *  
 * * * 
* * * *
 * * * 
  * *  
   *   

Hints and Guidelines

To solve this problem we need to mentally divide the rhombus into two parts - upper, which alsoincludes the middle row, and lower. For the printing of each part we will use two separate loops, as we leave the reader to decide the dependency between n and the variables of the loops. For the first loop we can use the following tips:

  • We print n-row white spaces.
  • We print *.
  • We print row-1 times *.

The second (lower) part will be printed similarly, which again we leave to the reader to do.

Testing in the Judge System

Test your solution here: https://judge.softuni.bg/Contests/Practice/Index/512#5.

results matching ""

    No results matching ""