я тут половину ромба нарисовал, вторую половину сам дорисуешь
Не знаю почему, но в примере fasked массив должен быть 6х6, тогда не будет переполнения
C++ |
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
| #include <iostream>
#include <string>
using namespace std;
int main()
{
int N; cin >> N;
char spaces[] = " ";
char shape [20];
int margine = N-1; int asterN = 1;
// ****************рисуем первую звездочку****************
strncpy(shape,spaces,margine); shape[N-1] = '\0';
strcat(shape,"*"); shape[N] = '\0';
strncat(shape,spaces,margine); shape[N*2-1] = '\0';
cout << shape << endl ;
//**************************************************************
int middle = 1;
while(margine)
{
strncpy(shape,spaces,margine-1); shape[margine-1] = '\0';
strcat(shape,"*"); shape[N] = '\0';
strncat(shape,spaces,middle); shape[N+middle] = '\0';
strcat(shape,"*"); shape[N+middle+1] = '\0';
strncat(shape,spaces,margine-1); shape[N*2-1] = '\0';
cout << shape << endl;
margine--;
middle += 2;
}
system("pause");
} |
|