| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

#include<stdio.h>
struct Data{
int year;
int month;
int day;
char name[20];
int age;
};
struct Data sd[5]={{2021,9,1,"zhangshan",18},{2021,9,1,"lisi",19},{2020,9,20,"wanghu",20},
{2020,9,23,"liubin",20},{2019,9,30,"hudayong",21}};
int main()
{
void input(struct Data sd[5]);
struct Data*p;
printf("年. 月 .日 .姓名 年龄. 平均年龄\n");
for(p=sd;p<sd+5;p++)
printf("%4d %d %d %-20s %2d %d\n",p->year,p->month,p->day,p->nam,p->age,p->arrage);
return 0;
}
void input(struct Data sd[5])
{
sd[5].arrage=(sd[5].a[0]+sd[5].a[1]+sd[5].a[2]+sd[5].a[3]+sd[5].a[4])/3;
}

1.学好汉语，让别人知道你在说什么
2.学点英语，知道编程器提示的是什么

[此贴子已经被作者于2021-1-13 22:20编辑过]

```#include <stdio.h>

struct Data {
int year;
int month;
int day;
char name[20];
int age;
};

double average_age( const struct Data sd[], size_t n );

int main( void )
{
struct Data sd[5] = { {2021, 9,  1, "zhangshan", 18}
, {2021, 9,  1, "lisi",      19}
, {2020, 9, 20, "wanghu",    20}
, {2020, 9, 23, "liubin",    20}
, {2019, 9, 30, "hudayong",  21} };

printf("%-4s %2s %2s %-20s %s\n", "年", "月", "日", "姓名", "年龄" );
for( size_t i=0; i!=sizeof(sd)/sizeof(*sd); ++i )
printf( "%4d %2d %2d %-20s %4d\n", sd[i].year, sd[i].month, sd[i].day, sd[i].name, sd[i].age );
printf( "平均年龄: %.1f\n", average_age(sd,sizeof(sd)/sizeof(*sd)) );
}

double average_age( const struct Data sd[], size_t n )
{
double sum = 0;
for( size_t i=0; i!=n; ++i )
sum += sd[i].age;
return n!=0 ? sum/n : 0;
}```
• 5
• 1/1页
• 1

Powered by Discuz, Processed in 0.062384 second(s), 8 queries.
Copyright©2004-2021, BCCN.NET, All Rights Reserved