How to input Diamond like this
input : 5
output :
Attachment 16134
Printable View
How to input Diamond like this
input : 5
output :
Attachment 16134
Are you sure you mean input, not output?
To input, get atext editor, set the font to monspaced, and type in the pattern.
The pass the name of the file on the commandline, open it with fopen(argv[1], "r"),
read each line with fgets(), and close with fclose();
If you want to generate a a pattern line that, which is what I think that
you really want to do, most likely, the rules are that if a point is
on the edge of the diamond, or on a vertical or horizontal centreline, is
is a "O", else it is a ".". So loop in y and in x over the square. Then you'll
need some logic to decide whether to write an "O" or not. You can experiment
with different approaches until it comes right.
You start by breaking the problem down into simpler problems.
Like for example, by trying to draw a cross and then an empty diamond
Code:....0.....
....0.....
....0.....
....0.....
000000000.
....0.....
....0.....
....0.....
....0.....
....0.....
...0.0....
..0...0...
.0.....0..
0.......0.
.0.....0..
..0...0...
...0.0....
....0.....
start with fibonnaci numbers/positioning and improve diamond from there
Attachment 16138Code:#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// maxDiamondSize = (maxLength/2)
#define maxLength 256
#define marker 'O'
#define spacer '.'
void drawDiamond(int size);
int main(int varc, char *argv[]) {
//int diamondSize = atoi(argv[1]);
//drawDiamond( diamondSize );
drawDiamond(5);
return 0;
}
void drawDiamond(int size) {
int count = 0, msize = (size), csize = (size-1);
char lineData[maxLength];
char lines[maxLength][maxLength];
while (size > 0) {
lineData[0] = '\0';
if (count != (msize-1)) {
for (int i=0;i<(msize*2);i++) lineData[i] = spacer;
lineData[csize-count] = marker;
lineData[csize] = marker;
lineData[csize+count] = marker;
lineData[msize*2] = '\0';
} else {
for (int i=0;i<((msize*2)-1);i++) lineData[i] = marker;
}
strcpy(lines[count],lineData); size--; count++;
}
for (int i=0; i<(msize-1); i++) printf("%s\n",lines[i]);
for (int i=(msize-1); i>(-1); i--) printf("%s\n",lines[i]);
}
:cool:
So instead of learning how to solve a problem, the OP has learnt that eventually, some schmuck will do their work for them.
Quote:
some schmuck
Attachment 16139