본문으로 바로가기

rep3

category c++/대학 과제 2020. 5. 25. 07:07
주어진 결과값

 

내가 푼답

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
	int i, j;

	cout << setw(45) << "구 구 단   출 력" << endl << setw(45) << "================" << endl << endl;

	for (i = 2; i <= 5; i++) {
		cout << setw(13) << i << " 단";
	}
	
	cout << endl << setw(8);

	for (i = 0; i <= 62; i++) {
		cout << '-';
	}

	for (i = 1; i <= 9; i++) {
		cout << endl << setw(10);
		for (j = 2; j <= 5; j++) {
			cout << j << " * " << i << " = " << setw(2) << j * i << setw(7);
		}
	}

	cout << endl << endl << endl;

	for (i = 6; i < 10; i++) {
		cout << setw(13) << i << " 단";
	}
	cout << endl << setw(8);

	for (i = 0; i <= 62; i++) {
		cout << '-';
	}

	for (i = 1; i <= 9; i++) {
		cout << endl << setw(10);
		for (j = 6; j <= 9; j++) {
			cout << j << " * " << i << " = " << setw(2) << j * i << setw(7);
		}
	}
}

 
 

교수님의 답

 #include <iostream>
 #include <iomanip>
 using namespace std; 
 void main()
 { 
	 int i, j, k, dan;
//	 cout<<"123456789012345678901234567890123456789++987654321098765432109876543210987654321";
	 cout<<"\t\t\t       구 구 단   출 력\n\t\t\t       ================\n\n";
	 for (i=1; i<=2; i++) {
		 k=i*4-2;
		 cout<<setw(12)<<k<<"  단"<<setw(14)<<k+1<<"  단"<<setw(14)<<k+2<<"  단"<<setw(14)<<k+3<<"  단\n";
//		 cout<<"\t----------------------------------------------------------------\n";
		 cout<<"\t"<<setfill('-')<<setw(64)<<"-"<<endl<<setfill(' ');
		 for(j=1; j<=9; j++) {
			 for(dan=k; dan<=k+3; dan++) cout<<setw(9)<<dan<<" * "<<j<<" = "<<setw(2)<<dan*j; 
			 cout<<"\n";
		 }
		 cout<<"\n\n";
	 }
 }

'c++ > 대학 과제' 카테고리의 다른 글

rep5  (0) 2020.05.25
rep4  (0) 2020.05.25
rep2  (0) 2020.05.25
rep1  (0) 2020.05.25
rep 0  (0) 2020.05.25