结构体 练习1

1

#include "stdio.h"

struct book{
	char title[50];
	char author[50];
	float value;
}library;
main(){
    struct book library;
    printf("now erter the book title");
    gets(library.title);
    printf("now erter the author");
    gets(library.author);
    printf("now enter the value.\n");
    scanf("%f",&library.value);
    printf("%s by %s : $%.2f\n",library.title,library.author,library.value);
    printf("%s by %s : $%.2f\n",library.author,library.title,library.value);
    printf("done.\n");

        

}

2

#include "stdio.h"
#define len 20
const char msgs[5][50]={/*也可为 *msgs[5](指针约等于数组 c 254页) 与msgs[5][50]相同 */
	"thank you for the wonderful evening,",
	"you certainly prove that a ",
	"is a special kind of guy, we must get togher",
	"over a delicious ",
	" and have a few laughs "
};
struct names{
	char first[len];
	char last[len];
};
struct guy{
	struct names handle;
	char favfood[len];
	char job[len];
	float income;
};
int main(void){
	struct guy fellow={
		{"ewen","villard"},
		"grilled salmon",
		"personality coach",
		58112.00
	};
	printf("dear %s, \n\n",fellow.handle.first);
	printf("%s%s.\n",msgs[0],fellow.handle.first);
	printf("%s%s.\n",msgs[1],fellow.job);
	printf("%s\n",msgs[2]);
	printf("%s%s%s",msgs[3],fellow.favfood,msgs[4]);
	if(fellow.income>150000.0)
	  puts("!!");
	else if(fellow.income>75000.0)
	  puts("!");
	else 
	  puts(".");
	printf("\n%40s%s\n"," ","see you soon, "); 
	printf("%40s%s\n,"," ","shalala");
	return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值