-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
미해결
강의 마지막 문제입니다.
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;
}
답변을 작성해보세요.
0
답변 1