Pattern
-
Hello every one ..emm a beginner in progmming . And I have a problem while printing a asterisks patter pattern is : i have to print the patter as per th user input like {3,2,4} * * * * * * * * * this pattern should be for n inputs.MY problem is after printing a vertical line how could i go back to top to print another line. I have understood that first i have to find the max among all the inputs then have to print the max-input no blank in every vertical line but i dnn knw how can i print vertically :confused:
Well the numbers (3,2,4) don't seem to match your pattern anywhere so it is difficult to see the connection between the two. However, in order to print patterns of stars you print rows first. So it is just a matter of using the counts to decide how many to print on each row. If you try figuring out how you would do it using pen and paper, then coverting that to code should be quite easy.
Veni, vidi, abiit domum
-
Hello every one ..emm a beginner in progmming . And I have a problem while printing a asterisks patter pattern is : i have to print the patter as per th user input like {3,2,4} * * * * * * * * * this pattern should be for n inputs.MY problem is after printing a vertical line how could i go back to top to print another line. I have understood that first i have to find the max among all the inputs then have to print the max-input no blank in every vertical line but i dnn knw how can i print vertically :confused:
If I understand you post your 'algorithm' is incorrect. You do not print vertically - Instead you print horizontally. Hopefully you have already learned about loops and arrays. So 1. Put the values in an array 2. Write a method that finds the maximum value in the array. When if finds it set the array location to -1 (this is how you 'remove' it.) 3. Write a method that takes a X value and prints that many stars. 4. Put 2 and 3 together to print all the rows. 5. Think about how you know it will end (the '-1' is a hint.)
-
Well the numbers (3,2,4) don't seem to match your pattern anywhere so it is difficult to see the connection between the two. However, in order to print patterns of stars you print rows first. So it is just a matter of using the counts to decide how many to print on each row. If you try figuring out how you would do it using pen and paper, then coverting that to code should be quite easy.
Veni, vidi, abiit domum
-
If I understand you post your 'algorithm' is incorrect. You do not print vertically - Instead you print horizontally. Hopefully you have already learned about loops and arrays. So 1. Put the values in an array 2. Write a method that finds the maximum value in the array. When if finds it set the array location to -1 (this is how you 'remove' it.) 3. Write a method that takes a X value and prints that many stars. 4. Put 2 and 3 together to print all the rows. 5. Think about how you know it will end (the '-1' is a hint.)
-
opp!!! that was my typing mistake first i want to print the 3 stars then 2 and then 4 means basically depending upon the oder of input given by user ..
-
So what is the problem? Just use each number to create a loop and print that number of stars.
Veni, vidi, abiit domum
i have to print the stars in vertical manner mean first three stars vertical line then 4 stars vertical line and so on basically like the tower of asterisks . the problem is that after printing a line how can i take back control to the top to print another asterisks tower ??
-
i have to print the stars in vertical manner mean first three stars vertical line then 4 stars vertical line and so on basically like the tower of asterisks . the problem is that after printing a line how can i take back control to the top to print another asterisks tower ??
-
i have to print the stars in vertical manner mean first three stars vertical line then 4 stars vertical line and so on basically like the tower of asterisks . the problem is that after printing a line how can i take back control to the top to print another asterisks tower ??
Try changing your approach to the problem. Let's try this. Input : 2, 4, 3 Desired output:
*
**
***
***For graphical purposes let me remake the output as follows
*OO
**O
***
***Replace the "O" with spaces. Does it help? -chronodekar
-
Try changing your approach to the problem. Let's try this. Input : 2, 4, 3 Desired output:
*
**
***
***For graphical purposes let me remake the output as follows
*OO
**O
***
***Replace the "O" with spaces. Does it help? -chronodekar
-
There might be a more efficient way of doing it, but here's my thinking. 1. Arrange all the numbers in descending order. Make note of the largest one ( = A). Also store the numbers in an array ( = ARRAY) 2. Count the number of inputs ( = B). 3. Visualize the output in the form of a rectangle - you need to draw (with ASCII) a rectangle whose height is A and width B. Alternatively, you need to print A no. of lines with B characters. Now we come to implementation. In pseudo-code;
for (i = A ; i>0; i--)
{
for (j = 0; j i)
print("*");
else
print("O");
}
print("\n");
}I think that should do it. Any edge case I missed? -chronodekar