Консультация № 124476
23.02.2008, 13:21
0.00 руб.
0 2 2
Помогите, пожалуйста, выполнить задание. Корона должна выводиться на консоли, знаком "*"

Приложение:
25. Вывести корону. Высоту задает пользователь.* * *** *** ***** ***** ****************

Обсуждение

Неизвестный
24.02.2008, 13:07
общий
это ответ
Здравствуйте, VIP VIP!

Вот решение задачи. Для порядку конечно стоит еще добавить проверку вводимого числа (оставляю на ваше усмотрение)

Приложение:
# include <stdio.h>void print_line(char ch,unsigned int count){ for (; count> 0; --count) printf("%c",ch);}void main(){ unsigned int N = 5; printf("Height:"); scanf("%d",&N); unsigned int stars1 = 1,stars2 = 1, spaces = 1 + (N-2)*2; for (unsigned int i=0; i<N-1; ++i) { print_line(‘*‘,stars1); print_line(‘ ‘,spaces); print_line(‘*‘,stars2); print_line(‘ ‘,spaces); print_line(‘*‘,stars1); stars1++; stars2+= 2; spaces -= 2; printf("\n"); } print_line(‘*‘,3 + (1 + (N-2)*2)*2); printf("\n");}
Неизвестный
24.02.2008, 19:32
общий
это ответ
Здравствуйте, VIP VIP!
Код в приложении, компилировался в VS 2003


Приложение:
#include <iostream>#include <conio.h>using namespace std;void main(){ int height; cout<<"vvedite visotu coroni - "; cin>>height; int x=0,y,z; z=(height*2+(height*2-2)); y=z/2-1; char **Array=new char*[height]; for(int i=0; i<height; i++) { Array[i]=new char[height*2+(height*2-2)]; for(int j=0; j<(height*2+(height*2-2)-1); j++) { if(((x+i)>=j)||(z-i)<=(j+2)||((y-i<=j)&&(y+i>=j))) { Array[i][j]=‘*‘; } else { Array[i][j]=‘ ‘; } cout<<Array[i][j]; } cout<<"\n"; } for(int i=0; i<height; i++) { delete [] Array[i]; } delete [] Array; getch();}
Форма ответа