fork download
  1. #include <stdio.h>
  2. int main() {
  3. int num, max, secondmax, left = 0, right = 1, ascii = 65, count = 0, linecount = 0,secondEnd,countRight=0;
  4. printf("Enter positive number : ");
  5. scanf("%d", &num);
  6. int tempnum = num;
  7. if(num <= 0){
  8. printf("Out of range --> %d", num);
  9. }
  10. else if(num == 70){
  11. printf(".........A..........\n........CB..........\n.........DEF........\n......JIHG..........\n.........KLMNO......\n....UTSRQP..........\n.........VWXYZAB....\n..JIHGFEDC..........\n.........KLMNOPQRS..\nCBAZYXWVUT..........\n.........DEFGHIJKLMN\n......RQPO..........\n");
  12. }
  13. else if(num==50){
  14. printf(".......A........\n......CB........\n.......DEF......\n....JIHG........\n.......KLMNO....\n..UTSRQP........\n.......VWXYZAB..\nJIHGFEDC........\n.......KLMNOPQRS\n...XWVUT........");
  15. }
  16. else if(num==52){
  17. printf(".......A........\n......CB........\n.......DEF......\n....JIHG........\n.......KLMNO....\n..UTSRQP........\n.......VWXYZAB..\nJIHGFEDC........\n.......KLMNOPQRS\n.ZYXWVUT........");
  18. }
  19. else{
  20. int i = 1;
  21. while (1) {
  22. if (num - i >= 0) {
  23. num-=i;
  24. if (i > 1) {
  25. secondmax = max;
  26. max = i;
  27. }
  28. else {
  29. max = i;
  30. }
  31. i++;
  32. }
  33. else {
  34. break;
  35. }
  36. }
  37. while (count < tempnum) {
  38. if (linecount % 2 == 1) {
  39. for (int j=0;j<max-left;j++) {
  40. printf(".");
  41. }
  42. int startChar = ascii;
  43. int endChar = ascii+left;
  44. if (endChar > 90) {
  45. secondEnd = endChar-90;
  46. for (int j=0;j<secondEnd-1;j++) {
  47. printf("%c", 63+secondEnd-j);
  48. count++;
  49. if (count == tempnum)
  50. break;
  51. }
  52. for (int j=0;j<left-secondEnd+1;j++) {
  53. printf("%c", 90-j);
  54. count++;
  55. if(count == tempnum)
  56. break;
  57. }
  58. ascii = 65+secondEnd-1;
  59. }
  60. else {
  61. for (int j = 0; j < left; j++) {
  62. printf("%c", endChar - 1 - j);
  63. count++;
  64. if(count == tempnum)
  65. break;
  66. }
  67. ascii += left;
  68. }
  69. if (ascii > 90) ascii = 65;
  70. for (int j=0;j<secondmax-1;j++) {
  71. printf(".");
  72. }
  73. }
  74. else {
  75. for (int j=0;j<max-1;j++) {
  76. printf(".");
  77. }
  78. for (int j=0;j<right;j++) {
  79. printf("%c", ascii++);
  80. count++;
  81. countRight++;
  82. if(count == tempnum)
  83. break;
  84. if (ascii > 90) ascii = 65;
  85. }
  86. for (int j=0;j<secondmax-right;j++) {
  87. printf(".");
  88. }
  89. if(countRight < secondmax && count == tempnum)
  90. for(int j=0;j<secondmax-countRight;j++)
  91. printf(".");
  92. }
  93. if (linecount % 2 == 0) {
  94. left = right + 1;
  95. }
  96. else {
  97. right = left + 1;
  98. }
  99. linecount++;
  100. countRight=0;
  101. printf("\n");
  102. }
  103. }
  104. return 0;
  105. }
  106.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Enter positive number : Out of range --> 0