Please help me with the program code

Reply

Join Date: Jun 2009
Posts: 13
Reputation: shakeelahmed22 is an unknown quantity at this point 
Solved Threads: 0
shakeelahmed22 shakeelahmed22 is offline Offline
Newbie Poster

Please help me with the program code

 
0
  #1
Jun 3rd, 2009
I need to write a program to print the below pattern of * representing the alphabet X.
I am unable to print an X using asterisks in the post.
I hope you can understand the below explanation.
The X should have 7 rows - with three rows at the top and 3 at the bottom. Each row holds 2 *.

* *
* *
* *
*
* *
* *
* *

Please Help !!!!!!!!!!!!!!!
Last edited by shakeelahmed22; Jun 3rd, 2009 at 3:58 pm. Reason: unable to print an X with *
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 87
Reputation: freelancelote is an unknown quantity at this point 
Solved Threads: 2
freelancelote's Avatar
freelancelote freelancelote is offline Offline
Junior Poster in Training

Re: Please help me with the program code

 
0
  #2
Jun 3rd, 2009
did you do any code already?
can you post it?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,813
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Please help me with the program code

 
0
  #3
Jun 3rd, 2009
Originally Posted by shakeelahmed22 View Post
I need to write a program to print the below pattern of * representing the alphabet X.
I am unable to print an X using asterisks in the post.
I hope you can understand the below explanation.
The X should have 7 rows - with three rows at the top and 3 at the bottom. Each row holds 2 *.

* *
* *
* *
*
* *
* *
* *

Please Help !!!!!!!!!!!!!!!

Use code tags. It preserves formatting.


[code]
// paste *'s here
[/code]


  1. * *
  2. * *
  3. * *
  4. *
  5. * *
  6. * *
  7. * *

Each row holds 2 *.
Looks like the middle row only holds one.

You should use a nested for-loop (a for loop within another for loop).
Last edited by VernonDozier; Jun 3rd, 2009 at 4:04 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 13
Reputation: shakeelahmed22 is an unknown quantity at this point 
Solved Threads: 0
shakeelahmed22 shakeelahmed22 is offline Offline
Newbie Poster

Re: Please help me with the program code

 
0
  #4
Jun 3rd, 2009
Thanks for the prompt response... I do understand that it can be done through nested loops.. but can you specify the conditions for the FOR and the nested FOR loop.

Thanks once again.

Shakeel
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 13
Reputation: shakeelahmed22 is an unknown quantity at this point 
Solved Threads: 0
shakeelahmed22 shakeelahmed22 is offline Offline
Newbie Poster

Re: Please help me with the program code

 
0
  #5
Jun 3rd, 2009
The pattern is as below
  1. * *
  2. * *
  3. * *
  4. *
  5. * *
  6. * *
  7. * *
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: Please help me with the program code

 
0
  #6
Jun 3rd, 2009
A simple solution:

  1. int draw()
  2. {
  3. int pat[7][7] = { 1, 0, 0, 0, 0, 0, 1,
  4. 0, 1, 0, 0, 0, 1, 0,
  5. 0, 0, 1, 0, 1, 0, 0,
  6. 0, 0, 0, 1, 0, 0, 0,
  7. 0, 0, 1, 0, 1, 0, 0,
  8. 0, 1, 0, 0, 0, 1, 0,
  9. 1, 0, 0, 0, 0, 0, 1
  10. };
  11.  
  12. int i, j;
  13.  
  14. for(i = 0; i < 7; i++)
  15. {
  16. for(j = 0; j < 7; j++)
  17. {
  18. if(pat[i][j] == 1)
  19. {
  20. System.out.print("*");
  21. }
  22. else
  23. {
  24. System.out.print(" ");
  25. }
  26. }
  27. System.out.print("\n");
  28. }
  29. return 0;
  30. }
Last edited by Luckychap; Jun 3rd, 2009 at 5:27 pm.
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,439
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 510
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Please help me with the program code

 
0
  #7
Jun 3rd, 2009
Well, sure, except for three things:
1) it's C and this is the Java forum
2) If you are going to hard-code the whole pattern, why would you bother to use 1 and 0 to encode it just so you can translate it back with if() statements to the '*' you want to print? You may as well just put the asterisks in an array and print it in that case.
3) I would assume figuring out the loop logic is a goal of the assignment.
Last edited by Ezzaral; Jun 3rd, 2009 at 5:30 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 13
Reputation: shakeelahmed22 is an unknown quantity at this point 
Solved Threads: 0
shakeelahmed22 shakeelahmed22 is offline Offline
Newbie Poster

Re: Please help me with the program code

 
0
  #8
Jun 4th, 2009
hey luckychap thanx 4 da reply...bt i m still having a problem wid it....
look this is what i tried
  1. class pattern
  2. {
  3. void disp()
  4. {
  5. int a[7][7]={{*,0,0,0,0,0,*},
  6. {0,*,0,0,0,*,0},
  7. {0,0,*,0,*,0,0},
  8. {0,0,0,*,0,0,0},
  9. {0,0,*,0,*,0,0},
  10. {0,*,0,0,0,*,0},
  11. {*,0,0,0,0,0,*}};
  12. for(int i = 0;i<7;i++)
  13. {
  14. for int(j = 0; j<7;j++)
  15. {
  16. if(a[i][j] == '*')
  17. System.out.print("*");
  18. else
  19. System.out.print(" ");
  20. }
  21. System.out.println();
  22. }
  23. }
  24. }
evryime i try 2 compile this program its displaying
']' expected
....i dont understand it...
what shall i do now????
n also i think ezzaral has a point when he says we can simply put the asterisks in the array n print it
Last edited by Tekmaven; Jun 4th, 2009 at 3:15 pm. Reason: Code Tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 9
Reputation: legilimen is an unknown quantity at this point 
Solved Threads: 2
legilimen legilimen is offline Offline
Newbie Poster

Re: Please help me with the program code

 
0
  #9
Jun 4th, 2009
There is a syntax error in the second for loop..
the opening braces should be before "int"
Where your treasure is,
there will your heart be also
!!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 13
Reputation: shakeelahmed22 is an unknown quantity at this point 
Solved Threads: 0
shakeelahmed22 shakeelahmed22 is offline Offline
Newbie Poster

Re: Please help me with the program code

 
0
  #10
Jun 4th, 2009
hey thanx....i dint notice that before but i m still facing a problem....u c
int a[7][7]={{*,0,0,0,0,0,*},
this line is getting highlighted n i m still facing the same error!!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC