• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

강의 마지막 문제입니다.

22.05.01 20:16 작성 조회수 175

0

문제 1, 2, 3 은 교수님이 풀어주신 예제의 변형 문제입니다.

교수님의 예제 출력값

1  

1  2  

1  2  3  

1  2  3  4  

1  2  3  4  5 

-----------------------------------------------------------------------------------------------------------------------------

1.

원하는 출력값

1 2 3 4 5

1 2 3 4

1 2 3

1 2

1

 

#include <iostream>

using namespace std;

int main()

{ int outer_count = 5;

while(outer_count >= 0)

{

int inner_count = 1;

while(outer_count >= inner_count)

{

cout << inner_count++ << " ";

}

cout << endl;

--outer_count;

}

 

return 0;

}

-----------------------------------------------------------------------------------------------------------------------------

2.

원하는 출력값

5 4 3 2 1

5 4 3 2

5 4 3

5 4

5

 

#include <iostream>

using namespace std;

int main()

{ int outer = 1;

while(outer <= 5)

{

int inner = 5;

while(outer <= inner)

{

cout << inner << " ";

--inner;

}

 

cout << endl;

++outer;

}

return 0;

}

-----------------------------------------------------------------------------------------------------------------------------

3.

원하는 출력값

1 2 3 4 5 X

1 2 3 4 X

1 2 3 X

1 2 X

1 X

 

#include <iostream>

using namespace std;

int main()

{ int outer = 5;

 

while(outer >= 0)

{

int inner = 1;

 

while(outer >= inner)

{

cout << inner << " ";

inner++;

if(outer < inner)

cout << "X";

}

cout << endl;

outer--;

}

return 0;

}

-----------------------------------------------------------------------------------------------------------------------------

4. 구구단 프로그램

 

#include <iostream>

using namespace std;

int main()

{ int x;

cin >> x;

int y = 1;

 

while(y <= 9)

{

cout << x << "*" << y << "=" << x*y << endl;

y++;

}

return 0;

}

 

 

답변 1

답변을 작성해보세요.

0

강민철님의 프로필

강민철

2022.05.02

잘 작성하신듯 합니다 :) 

수고많으셨습니다.

wer070947님의 프로필

wer070947

질문자

2022.05.02

감사합니다