Loading

PTA|基础编程题目集|7-5

结果样式

------------------------------------
Province      Area(km2)   Pop.(10K)
------------------------------------
Anhui         139600.00   6461.00
Beijing        16410.54   1180.70
Chongqing      82400.00   3144.23
Shanghai        6340.50   1360.26
Zhejiang      101800.00   4894.00
------------------------------------

解题

按题目要求格式与内容输出即可
这个主要是格式控制,可以使用不同语言的格式控制语句进行格式化输出。

关键点

  • 宽度设置
  • (字符)占位补齐
  • 对齐方式
  • 也可以使用浮点数的方式进行输出

参考代码

//7-5.c
#include <cstdio>
int main()
{
	printf("%s\n","------------------------------------" );
	printf("%-11s   %s   %s\n", "Province","Area(km2)","Pop.(10K)");
	printf("%s\n","------------------------------------" );
	printf("%-11s   %9s   %s\n", "Anhui","139600.00","6461.00");
	printf("%-11s   %9s   %s\n", "Beijing","16410.54","1180.70");
	printf("%-11s   %9s   %s\n", "Chongqing","82400.00","3144.23");
	printf("%-11s   %9s   %s\n", "Shanghai","6340.50","1360.26");
	printf("%-11s   %9s   %s\n", "Zhejiang","101800.00","4894.00");
	printf("%s\n","------------------------------------" );
	
	return 0;
}
posted @ 2020-09-30 15:43  Devinwon  阅读(214)  评论(0编辑  收藏  举报