>  기사  >  백엔드 개발  >  사각형에 포함된 사각형을 인쇄하는 C 언어 프로그램을 작성하세요.

사각형에 포함된 사각형을 인쇄하는 C 언어 프로그램을 작성하세요.

王林
王林앞으로
2023-09-02 08:09:06995검색

프로그램 설명

아래 그림과 같이 다른 정사각형 안에 정사각형을 인쇄하세요

사각형에 포함된 사각형을 인쇄하는 C 언어 프로그램을 작성하세요.

Algorithm

Accept the number of rows the outer Square to be drawn
Display the Outer Square with the number of rows specified by the User.
Display another square inside the outer square.

Example

중국어 번역은 다음과 같습니다:

Example

/* Program to print Square inside Square */
#include <stdio.h>
int main()
{
   int r, c, rows;
   clrscr();
   printf("Enter the Number of rows to draw Square inside a Square: ");
   scanf("%d", &rows);
   printf("</p><p>");
   for (r = 1; r <= rows; r++){
      for (c = 1; c <= rows; c++){
         if ((r == 1 || r == rows || c == 1 || c == rows) || (r >= 3 && r <= rows - 2 && c >= 3 && c             <= rows - 2) && (r == 3 || r == rows - 2 || c == 3 || c == rows - 2)){
               printf("#");
         }
         else{
            printf(" ");
         }
      }
      printf("</p><p>");
   }
   getch();
   return 0;
}

Output

사각형에 포함된 사각형을 인쇄하는 C 언어 프로그램을 작성하세요.

위 내용은 사각형에 포함된 사각형을 인쇄하는 C 언어 프로그램을 작성하세요.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 tutorialspoint.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제