카테고리 없음

챕터 2: 과제 구구단 출력, 별찍기, 최대 최소값 찾기, 소수 판별하기, 숫자 맞히기, 틱택토

1vdlrwnsv1 2025. 1. 31. 23:30

구구단 출력 결과

for (int i = 2; i <=9; i++)
            for(int j = 1; j <=9; j++)
            {
                Console.WriteLine($"{i}*{j}={i * j}");
            }

 

별찍기

  for (int i = 1; i <= 5; i++)
        {
            Console.WriteLine(new string('*', i));
        }
        Console.WriteLine();
        for (int i = 5; i >= 1; i--)
        {
            Console.WriteLine(new string('*', i));
        }
        Console.WriteLine();
        for (int i = 1; i <= 5; i++) // 1부터 n까지 반복
        {
            string spaces = new string(' ', 5 - i);  // 왼쪽 공백 추가
            string stars = new string('*', 2 * i - 1); // 홀수 개의 별 출력
            Console.WriteLine(spaces + stars); // 공백 + 별을 합쳐 출력
        }