结构变量的初始化方式

input:

Pairs 2003 120 Chicago 2010 50000

#include <stdio.h>
#include <string.h>
struct Consumption
{
	char city[20];
	int year;
	double usage;
};
struct Resource
{
	char material[30];
	double longitude;
	double latitude;
	double quantity;
	char units[20];
};
int main()
{
	struct Resource metal,fuel;
	struct Resource wood={"Oak",32.5,13.2,5e+8,"hectares"};
	struct Consumption water,power;
	
	metal.longitude=57.3;
	metal.latitude=32.1;
	metal.quantity=3e+10;
	strcpy(metal.material,"Iron");
	strcpy(metal.units,"cubic metres");
	printf("The metal information is:\n%s\n%4.11f degree longitude\n"
	"%4.1lfdegree latitude\n%4.0e %s\n\n",metal.material,metal.longitude,metal.latitude,
	metal.quantity,metal.units);
	
	printf("Enter water and power:\ncity,year and usage\n");
	scanf("%s %d %lf %s %d %lf",water.city,&water.year,&water.usage,
	power.city,&power.year,&power.usage);
	
	printf("\n\nThe water and power are:\n%s\n%d\n%4.0lf million litress\n\n"
	"%s\n%d\n%4.0lf mega watts\n",
	water.city,water.year,water.usage,
	power.city,power.year,power.usage);
	return 0;
 } 

全部评论

相关推荐

看到要笑不活了,简历T恤二合一了&nbsp;再也不怕简历进入人才库了哈哈哈哈哈哈哈哈哈好
mingjuan:好笑在哪,美国经济危机的时候那个照片没看过吗,所有西装革履的中年男人把简历印在衣服上
点赞 评论 收藏
分享
08-05 11:21
已编辑
合肥工业大学 前端工程师
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务