Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to print following pattern?? any suggestions!

A A A B A A A
A A B B B A A
A B B B B B A
B B B B B B B
Posted

I would start writing all 'A's using two for loops. That should be trivial.
Then, based on the indices of the loops (say row, column) find the right if statement for printing either 'A' or 'B'.


[update]
See, for instance, C - if...else statement[^]. However I suggest you reading a good book on the C programming language.
[/update]
 
Share this answer
 
v3
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

But this is pretty trivial. Look at it: each row you need to print two more "B"s until you have printed no "A"a at all on that row. And the number of "A"s on each row becomes one less for the prefix and one less for the suffix each time.

So have a loop for the rows, and call a function to print the row - passing it the total number of characters to print, and the number of "B"s. Have it return the number of "A"s it printed. In the loop, check the return value, and if it's zero, exit the loop.

Done.
 
Share this answer
 
Comments
Mayuresh Deolekar 7-Aug-14 14:42pm    
sir i need suggestion only not expecting code.... thank you for your comment it seems helpful! :)
OriginalGriff 7-Aug-14 14:53pm    
You're welcome!
What you ned are formulas for either the number of As and Bs to print for each row, depending on the current index of the row, or formulas for the column numbers where you start and end printing Bs instead of As. To get an idea, write down the required numbers for each row, then find the formula behind these numbers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900