2017-12-03 21 views
-8

루핑과 관련하여 저는 초보자입니다. :( 저를 도와주세요C에서 do while 루프를 사용하여 패턴을 만들 수 있습니까?

질문 :. do 루프를 사용

는, 다음과 같은 패턴을 그린다. 내 나쁜 영어에 대한

* 
** 
*** 
**** 
***** 
+9

이건 학교 과제 같아. 너 혼자 해봤 니? –

+0

그냥 2 개의 중첩 된 do-loops로 시도해보십시오. 응답을 기다리지 마십시오. –

+0

이것은 튜토리얼 사이트가 아닙니다. [ask]를 읽고 [둘러보기] – Plutonix

답변

0
class MainClass 
{ 
    public static void Main (string[] args) 
    { 
     int counter = 1; 

     do { 

      for (int i = 0; i < counter; i++) { 
       Console.Write("*"); 
      } 
      Console.WriteLine(); // for newline 
      counter++; // increase counter 

     } while (counter < 6); 
    } 
} 

미안 당신이 할 수있는 do-while 루프의 카운터 사용

0

당신은 별 문자열을 생성하는 방법을 만들 수 있습니다 : 다음

public static string starGenerator(int count) 
{ 
    string stars = string.Empty; 
    for(int i = 0; i < count; i++) 
     stars += "*"; 

    return stars; 
} 

그리고 그것을 사용을 :

public static void Main(string[] args) 
{ 
    int counter = 1; 
    do 
    { 
     string stars = starGenerator(counter); 
     Console.WriteLine(stars); 

     counter++; 
    } while(counter <= 5); 
} 
0

do..while 주장하는 경우이를 구현하는 방법에는 여러 가지가 있습니다 :

string line = ""; 

do { 
    Console.WriteLine(line += "*"); 
} 
while (line.Length < 6);