B1036 跟奥巴马一起编程 (15 分)

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
    
    
	
	int num;
	char c;
	cin >> num >> c;
	
	int row = (double)num/2+0.5;
	
	//第一行 
	for(int i = 0; i < num; i++){
    
    
		cout << c;
	}
	cout << endl;
	
	//中间行数
	for(int i = 0; i < row - 2; i++){
    
    
		cout << c;
		for(int j = 0; j < num - 2; j++){
    
    
			cout << " ";
		}
		cout << c;
		cout << endl;
	}	
	
	for(int i = 0; i < num; i++){
    
    
		cout << c;
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/alovelypeach/article/details/113971220