#include<stdio.h>
#define BLANK ' '
void writePattern(char c1, char c2, char c3, char c4, char c5, int n1, int n2, int n3, int n4, int n5, int length);
void writeCharFixCount(char, int *, int *);
int main( void) {
char mark = '*';
char dot = '.';
int i;
int width, length;
int size;
int x = size;
//length == size;
//width == size;
printf("Please enter an integer in the range 1-8 both inclusive: ");
scanf("%d", &size);
for( i = 1; i <= size; i++){
writePattern('*','.',BLANK,BLANK,BLANK,1, size-1,0,0,0, size);
if (i = size-x)
writePattern( '*','.',BLANK, BLANK, BLANK, size-x,size-(size-x),0,0,0, size);
if (i = size-1)
writePattern( '*','.',BLANK, BLANK, BLANK, size-1,size-(size-1),0,0,0, size);
if (i= size)
writePattern('*','.',BLANK,BLANK,BLANK,size, size- size ,0,0,0, size);
}
return 0;
}
void writePattern(char c1, char c2, char c3, char c4, char c5,
int n1, int n2, int n3, int n4, int n5, int length) {
while ((n1 > 0) && (length > 0))
writeCharFixCount(c1, &n1, &length);
while ((n2 > 0) && (length > 0))
writeCharFixCount(c2, &n2, &length);
while ((n3 > 0) && (length > 0))
writeCharFixCount(c3, &n3, &length);
while ((n4 > 0) && (length > 0))
writeCharFixCount(c4, &n4, &length);
while ((n5 > 0) && (length > 0))
writeCharFixCount(c5, &n5, &length);
printf("\n"); /* advance the cursor to the beginning of a new line */
}
void writeCharFixCount(char c, int *count1, int *count2)
/* writes one copy of character c and decrements count1 and count2 */ {
printf("%c", c);
(*count1)--;
(*count2)--;
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
by: epasquierPosted on 2009-09-25 at 05:42:10ID: 25422348
First, I believe that
NK,BLANK,, BLANK,i,1, size-i-1,0 ,0, size);
NK,BLANK,, BLANK,size -i-1,1,i,0 ,0, size);
size-(size-x) = x
same for size-(size-1) = 1
your first pattern is done by
for( i = 1; i <= size; i++) writePattern(BLANK,'*',BLA
the second :
for( i = 1; i <= size; i++) writePattern(BLANK,'*',BLA
the third is complicated and the fourth is easy but I have something to do now I will get back to you in few minutes