943,695 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1136
  • C++ RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Sep 23rd, 2009
0

Re: void function

Hey. Seems like you've made some progress. Thanks great! Below is my solution but as noted previously, there are many. Hope it helps!

C++ Syntax (Toggle Plain Text)
  1. /**
  2.  * @file printV.c
  3.  * @description Prints a V shape.
  4.  **/
  5.  
  6. #include <stdio.h>
  7.  
  8. void printV(int);
  9.  
  10. int main() {
  11. printV(4); // Change # to change the number of rows.
  12. }
  13.  
  14. void printV(int numRows) {
  15. int i,j;
  16. int cols = (numRows * 2) - 1;
  17.  
  18. char vChar = '#';
  19. char emptyChar = ' ';
  20.  
  21. for(i=1; i <= numRows; i++) {
  22. for(j=1; j <= cols; j++) {
  23. if(i==j || i+j == numRows*2)
  24. printf("%c", vChar);
  25. else
  26. printf("%c", emptyChar);
  27. }
  28. printf("\n");
  29. }
  30. }
Reputation Points: 10
Solved Threads: 3
Junior Poster
Barefootsanders is offline Offline
165 posts
since Oct 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: [HELP]Adding string between text.
Next Thread in C++ Forum Timeline: glut still not working... much





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC