结构体 练习1

来源:互联网 发布:mac办公软件收费吗 编辑:程序博客网 时间:2024/06/03 09:25

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 20const 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;}


0 0
原创粉丝点击