"Topic link"
The subject asks you to write a program to print the given symbol into an hourglass shape. For example, given 17 "*", require printing in the following format
***** *** * ********
The so-called "hourglass shape" refers to the output of an odd number of symbols per line, the line symbol center alignment, the adjacent two lines sign number difference 2, the number of symbols from large to small order descending to 1, and then from small to large order increment;
Given any n symbols, it is not always possible to form an hourglass exactly. Require that the printed hourglass be able to use as many symbols as possible.
Input format:
The input gives 1 positive integers n (<=1000) and a symbol in one line, separated by a space in the middle.
Output format:
The largest hourglass shape consisting of a given symbol is printed first, and the number of symbols left unused in a row is finally output.
Input Sample:
19 *
Sample output:
* ********2
Submit Code:
1#include <stdio.h>2 3 intcount (N)4 {5 if(n = =1)6 return 1;7 Else8 returnCOUNT (n1)+4*n-2;9 }Ten One voidprintf_t (intNintNCharc) A { - inti; - if(n = =1) the { - for(i =0; i < n-n; i++) -printf" "); -printf"%c", c); +printf"\ n"); - return ; + } A Else at { - for(i =0; i < n-n; i++) -printf" "); - for(i =0; I <2*n-1; i++) -printf"%c", c); -printf"\ n"); inprintf_t (n, N1, c); - } to } + - voidPrintf_b (intNintNCharc) the { * inti; $ if(n = =N)Panax Notoginseng { - for(i =0; I <2* n +1; i++) theprintf"%c", c); +printf"\ n"); A return ; the } + Else - { $ for(i =0; i < n-n; i++) $printf" "); - for(i =0; I <2* n +1; i++) -printf"%c", c); theprintf"\ n"); -Printf_b (N, n+1, c);Wuyi } the } - Wu voidPrintf_n (intNCharc) - { About intI, J; $ - for(i = n; i >0; i--) - { - for(j = n-i; J >0; j--) Aprintf" "); + for(j =0; J <2I1; J + +) theprintf"%c", c); -printf"\ n"); $ } the the for(i =1; I < n; i++) the { the for(j = n-i; J >1; j--) -printf" "); in for(j =0; J <2* i +1; J + +) theprintf"%c", c); theprintf"\ n"); About } the } the the + intMainvoid) - { the CharC;Bayi intN, N, T1, T2; the thescanf"%d%c", &n, &c); - -n =1; the while(N >= (T1 =count (n))) the { then++; theT2 =T1; - } then--; the the //printf_t (n, N, c);94 //Printf_b (n-1, 1, c); the //printf ("%d", n-t2); the the printf_n (n, c);98printf"%d"NT2); About - return 0;101}
PAT (Basic level) practise:1027. Print Hourglass