Home » Ask & Discuss » Board Exams - CBSE, ICSE, State Boards » Computer Science « Back to Discussion



Computer Science

aparna ravi's Avatar
Cool goIITian

Joined: 22 Mar 2007
Post: 63
12 Apr 2009 22:42:26 IST
0 People liked this
3
340 View Post
a small C++ program
None

hey can someone just tell me the logic for this

to print the following pattern

*****1#####1

****2####2

***3###3

**4##4

*5#5


Share this article on:

Comments (3)

RyuAmakusa's Avatar

Blazing goIITian

Joined: 21 Mar 2008
Posts: 776
14 Apr 2009 13:32:02 IST
1 people liked this

see the pattern ....
INV:1<=i<=5 and u have printed
****1#####1
****2####2
****(6-i)times,i,####....(6-i)times,i
loop
{
}
assert: i = 6  and u have printed
*****1#####1
****2####2
***3###3
**4##4
*5#5
INV ...it is called the ivariant it is a condition which is always satisfied at that point at every iteration
assert:......it is what u can assertain that would have happened whaen the loop end and the control is transfered to that point
and the INV is basicaly the weakening of assert: ......did u understand it........it is not any language in comp sci but it is
the language of the algorithm...........the C++ or java or python...what ever.......are just a matter of syntax.......
what u really have to learn is this, once u have done this.....then u can say that u have learnt programming

14 Apr 2009 13:35:45 IST
0 people liked this

u can take the positions as 1st row 5th column,,,,n use the for loop with cout <<(the symbol u want to display)...u have to use a nested if else loop also...this program is nt easy....
Vikram Saxena's Avatar

Forum Expert
Joined: 1 Apr 2007
Posts: 3732
24 Apr 2009 08:36:01 IST
0 people liked this

for(i=1;i<=n;i++)
{
for(j=n;j>=i;j--)
printf("*");
printf("%d",i);
for(j=n;j>=i;j--)
printf("#");
}

 

 

-all the best for your future




Quick Reply


Reply

Some HTML allowed.
Keep your comments above the belt or risk having them deleted.
Signup for a avatar to have your pictures show up by your comment
If Members see a thread that violates the Posting Rules, bring it to the attention of the Moderator Team
Free Sign Up!

Preparing for IIT-JEE ?

Arihant Revision Package for IIT JEE - Books, Practice Tests + Rank Predictor


@ INR 1,995/-

For Quick Info

Name

Mobile No.

Find Posts by Topics

Physics.

Topics

Mathematics.

Chemistry.

Biology

Parents

Board

Fun Zone

Sponsored Ads