// Program4.c // CSE 130 Fall 2009. Homework 4 // Drawing Triangles using functions, November 10th, 2009. // Reza Basseda, Id-No: xxx-yy-zzzz #include // Function prototypes/declarations: int topLine(int); void initialBlanks(int); int twoX(int); int bottom(void); int drawTriangle(int); int main(void) // The main function called by operating functions. { int size, count; printf("Type in Triangle size: "); scanf("%d", &size); while (size != 0) // The while condition checks termination. { count = drawTriangle(size); printf("Total number of O's and x's is %d.\n", count); printf("Type in Triangle size: "); scanf("%d", &size); } return 0; } int topLine(int n) // This function draws the top line of triangle. { int i; printf("O"); for(i=0; i0 ; k--) printf(" "); printf("x"); printf("\n"); return 2; } int bottom(void) // This function draws the last vertex of triangle. { printf("O"); return 1; } int drawTriangle(int n) // This function manages the printing of triangle. { int count = 0, i; printf("\n"); count = count + topLine(n); for(i=1; i<=n; i++) { initialBlanks(i); count = count + twoX(2*n-(2*i-1)); //(2n-1),(2n-2),etc... } initialBlanks(n+1); count = count + bottom( ); printf("\n\n"); return count; }