Printing C templates

How do we print the following template in c? Inside another square there is a square that is again inside another square. So, there are only three squares.

-4
source share
1 answer

Here you go:

Code Sample List


#include <stdio.h>

#define NUM_SQUARES  (5)

int main(void) {
   int i,j;

   printf("###########\n");
   printf("#         #\n");
   printf("# ####### #\n");
   printf("# #     # #\n");
   printf("# # ### # #\n");
   printf("# # # # # #\n");
   printf("# # ### # #\n");
   printf("# #     # #\n");
   printf("# ####### #\n");
   printf("#         #\n");
   printf("###########\n");

   return 0;
}

Output result


###########
#         #
# ####### #
# #     # #
# # ### # #
# # # # # #
# # ### # #
# #     # #
# ####### #
#         #
###########
+2
source

All Articles