Search results
Dec 17, 2015 · by far the easiest approach is to iterate over 0 <= x <= size, 0 <= y <= size, and determine by the Manhattan Distance of the coordinate (x,y) - (size/2, size/2), if the point is within at the perimeter. Making an equation MIN <= distance <= MAX, one can control the thickness of the diamond. int i, j;
Aug 4, 2020 · 0. Think of a Cartesian coordinate system whose origin is the center of symmetry of the diamond pattern to be drawn. The 0 s reside in the lines y = x + (n - 1), y = -x + (n - 1), y = x - (n - 1), y = -x - (n - 1), and the axes y = 0, x = 0. Then we can easily codify this information to draw the diamond pattern: #include <stdio.h>.
best you can do is to reverse the code. for example if you are able to make half diamond then use "\n" that many times and reverse the loops and make the other half or diamond. – yadav22ji Commented Feb 21, 2017 at 17:58
Since the middle and largest row of stars has 9 stars, you should make n equal to 9. You were able to print out half of the diamond, but now you have to try to make a function that prints a specific number of spaces, then a specific number of stars.
May 5, 2012 · We know that in row 1, we need to print a space 10 times and a star one time. Once the row has the number of spaces and stars required, you go to the newline ("\n" or endl). But the next row you need to print 2 more stars and 1 less spaces. So you must increment/decrement appropriately.
Nov 20, 2022 · Here's the code of a solid diamond and I want to remove the middle and leave the edges. From this, to this, int i, j, count = 1, number; Console.Write("Enter number of rows:"); number = int.Parse(Console.ReadLine()); count = number - 1; for (j = 1; j <= number; j++) for (i = 1; i <= count; i++)
Oct 23, 2016 · you can save a lot of time by figuring out that (row<=n?row:(row-2*k)) doesn't depend on the inner loop variable
Nov 15, 2020 · I'm a beginner in C, I'm facing a problem in order to implement a diamond, I'm following guided exercises from a book but I got stuck, I have to implement the pattern: According to the exercise, they suggest me to implement the pattern using the operator % I coded the structure but when I want to implement the pattern @.o.@ I just destroy ...
Oct 11, 2013 · I can see what you are trying to do and this is a pretty neat way to think about the diamond. You will have some issues with the j counter when i goes negative..look at how to use Math.abs() Also try writing some pseudo code in basic steps with comments to get the pattern clear:
Mar 3, 2021 · for c in L+L[-2::-1] produces one row per character vertically based on the vertical order of characters (each character placed in c) for s in L[::-1]+L[1:] runs through the horizontal pattern to build each line (nested list) (' ',c)[c==s] selects spaces for every character in the horizontal pattern that doesn't match the line's letter.