void function

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Oct 2006
Posts: 164
Reputation: Barefootsanders is an unknown quantity at this point 
Solved Threads: 3
Barefootsanders Barefootsanders is offline Offline
Junior Poster

Re: void function

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

  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. }
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
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