C Primer Plus(第五版)第10章 数组和指针

10.1
#include <stdio.h>
#define MONTHS 12
#define YEARS 5
int main(void)
{
float rain[YEARS][MONTHS] =
{
{4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6},
{8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3},
{9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4},
{7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2},
{7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2}
};
int i=0;
float (* y)[12],*m;
float subtot, total;
printf(" YEAR RAINFALL (inches)\n");
for(y=rain,total=0;y<rain+5;y++)
{
for(m=*y,subtot=0;m<(float *)(y+1);m++)
subtot+=*m;
printf("%5d %15.1f\n", 2000 + i++, subtot);
total+=subtot;
}
printf("\nThe yearly average is %.1f inches.\n\n",
total/YEARS);
printf("MONTHLY AVERAGES:\n\n");
printf(" Jan Feb Mar Apr May Jun Jul Aug Sep Oct ");
printf(" Nov Dec\n");
for (i = 0; i < MONTHS; i++)
{
for (y = rain, subtot =0; y < rain+5; y++)
subtot += *(*y+i);
printf("%4.1f ", subtot/YEARS);
}
printf("\n");

return 0;
}

10.2
#include<stdio.h>
void copy_arr(double*,double*,int);
void copy_ptr(double*,double*,int);
int main(void)
{
double source[5]={1.1,2.2,3.3,4.4,5.5};
double target1[5];
double target2[5];
copy_arr(source,target1,5);
copy_ptr(source,target2,5);
int i;
for(i=0;i<5;i++)
printf("%f %f %f\n",source[i],target1[i],target2[i]);
return 0;
}
void copy_arr(double* s,double* t,int n)
{
int i;
for(i=0;i<n;i++)
t[i]=s[i];
}
void copy_ptr(double* s,double* t,int n)
{
double*p=t;
while(t<p+n)
{
*t=*s;
t++,s++;
}
}

10.3
#include<stdio.h>
int greatest(int*,int);
int main(void)
{
int size;
int i=0,g;
printf("please,input the array size.\n");
while(scanf("%d",&size)!=1)
{
while(getchar()!='\n')
;
printf("wrong,do it again.\n");
}
int a[size];
again:
printf("please,input the every array value,according to the size above.\n");
while(i<size&&scanf("%d",&a[i]))
i++;
if (i!=size)
{
printf("the input is wrong ,do it again.\n");
while(getchar()!='\n')
;
goto again;
}
g=greatest(a,size);
printf("the greatest number is %d.\n",g);
return 0;
}
int greatest(int*p,int n)
{
if (n==1) return p[0];
else
{
int i=0;
for(i=0;i<n-1;i++)
p[i+1]=p[i]>p[i+1]?p[i]:p[i+1];
return p[n-1];
}
}

10.4
#include<stdio.h>
int greatest(double*,int);
int main(void)
{
int size;
int i=0,g;
printf("please,input the array size.\n");
while(scanf("%d",&size)!=1)
{
while(getchar()!='\n')
;
printf("wrong,do it again.\n");
}
double a[size];
again:
printf("please,input the every array value,according to the size above.\n");
while(i<size&&scanf("%lf",&a[i]))
i++;
if (i!=size)
{
printf("the input is wrong ,do it again.\n");
while(getchar()!='\n')
;
goto again;
}
g=greatest(a,size);
printf("the index of the greatest number is %d.\n",g);
return 0;
}
int greatest(double*p,int n)
{
double *g,*h;
*g=*p;
h=p;
if (n==1) return n;
else
{
while(p<h+n)
{
g=*g>*p?g:p;
p++;
}
return g-h;
}
}

10.5
#include<stdio.h>
double different(double*,int);
int main(void)
{
int size;
int i=0;
double g;
printf("please,input the array size.\n");
while(scanf("%d",&size)!=1)
{
while(getchar()!='\n')
;
printf("wrong,do it again.\n");
}
double a[size];
again:
printf("please,input the every array value,according to the size above.\n");
while(i<size&&scanf("%lf",&a[i]))
i++;
if (i!=size)
{
printf("the input is wrong ,do it again.\n");
while(getchar()!='\n')
;
goto again;
}
g=different(a,size);
printf("the difference between greatest and smallest is %g.\n",g);
return 0;
}
double different(double*p,int n)
{
double *g,*s,*h;
*g=*p;
*s=*p;
h=p;
if (n==1) return 0;
else
{
while(p<h+n)
{
g=*g>*p?g:p;
s=*s>*p?p:s;
p++;
}
return *g-*s;
}
}

10.6
#include<stdio.h>
void copy_arr(double*,double*,int);
int main(void)
{
int i,j;
double a[5][12]=
{
{4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6},
{8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3},
{9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4},
{7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2},
{7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2}
};
double b[5][12];
for(i=0;i<5;i++)
copy_arr(a[i],b[i],12);
for(i=0;i<5;i++)
{
for(j=0;j<12;j++)
{
printf("%g %g\n",b[i][j],a[i][j]);
}
}
return 0;
}
void copy_arr(double* s,double* t,int n)
{
int i;
for(i=0;i<n;i++)
t[i]=s[i];
}

10.7
#include<stdio.h>
void copy_arr(double*,double*,int);
int main(void)
{
int i;
double a[7]={4.3,0.4,2.4,3.5,6.6};
double b[3];
copy_arr(a+2,b,3);
for(i=0;i<3;i++)
printf("%g %g\n",b[i],a[i+2]);
return 0;
}
void copy_arr(double* s,double* t,int n)
{
int i;
for(i=0;i<n;i++)
t[i]=s[i];
}

10.8
#include<stdio.h>
void copy_arr(int,int,double(*)[*],double(*)[*]);
void copy_test(int,int,double(*)[*],double(*)[*]);
int main(void)
{
double a[3][5]={{1,2,3},{4,5,6},{0,5,9}};
double b[3][5];
copy_arr(3,5,a,b);
copy_test(3,5,a,b);
return 0;
}
void copy_arr(int i,int j,double(*s)[j],double(*t)[j])
{
int g,h;
for(g=0;g<i;g++)
for(h=0;h<j;h++)
t[g][h]=s[g][h];
}
void copy_test(int i,int j,double(*s)[j],double(*t)[j])
{
int g,h;
for(g=0;g<i;g++)
for(h=0;h<j;h++)
printf("%f %f\n",s[g][h],t[g][h]);
}

10.9
#include<stdio.h>
void add(int*,int*,int*,int );
int main(void)
{
int i;
int a[4]={2,4,5,8};
int b[4]={1,0,4,6};
int c[4];
add(a,b,c,4);
for(i=0;i<5;i++)
printf("%d %d %d\n",a[i],b[i],c[i]);
return 0;
}
void add(int*s1,int*s2,int*t,int l)
{
int i;
for(i=0;i<l;i++)
t[i]=s1[i]+s2[i];
}

10.10
#include<stdio.h>
void show(int(*)[5],int);
void doublev(int(*)[5],int);
int main(void)
{
int i,j;
int a[3][5];
for(i=0;i<3;i++)
for(j=0;j<5;j++)
a[i][j]=i*5+j;
show(a,3);
doublev(a,3);
show(a,3);
return 0;
}
void show(int(*s)[5],int l)
{
int i,j;
for(i=0;i<l;i++)
{
for(j=0;j<5;j++)
printf("%d ",s[i][j]);
printf("\n");
}
}
void doublev(int(*s)[5],int l)
{
int i,j;
for(i=0;i<l;i++)
for(j=0;j<5;j++)
s[i][j]*=2;
}

10.11
#include <stdio.h>
#define MONTHS 12
#define YEARS 5
void showm(float(*)[12],int);
void showy(float(*)[12],int);
int main(void)
{
float rain[YEARS][MONTHS] =
{
{4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6},
{8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3},
{9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4},
{7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2},
{7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2}
};
showm(rain,YEARS);
showy(rain,YEARS);
return 0;
}
void showm(float(*rain)[12],int row)
{
int i=0;
float (* y)[12],*m;
float subtot, total;
printf(" YEAR RAINFALL (inches)\n");
for(y=rain,total=0;y<rain+row;y++)
{
for(m=*y,subtot=0;m<(float *)(y+1);m++)
subtot+=*m;
printf("%5d %15.1f\n", 2000 + i++, subtot);
total+=subtot;
}
printf("\nThe yearly average is %.1f inches.\n\n",
total/row);
}
void showy(float(*rain)[12],int row)
{
int i=0;
float (* y)[12];
float subtot;
printf("MONTHLY AVERAGES:\n\n");
printf(" Jan Feb Mar Apr May Jun Jul Aug Sep Oct ");
printf(" Nov Dec\n");
for (i = 0; i < MONTHS; i++)
{
for (y = rain, subtot =0; y < rain+row; y++)
subtot += *(*y+i);
printf("%4.1f ", subtot/row);
}
printf("\n");
}

10.12 and 10.13
#include <stdio.h>
void input(int,int,double(*)[*]);
void averageperarray(int,int,double(*)[*]);
void greatest(int,int,double (*)[*]);
int main(void)
{
int r,c;
printf("please,input 2 numbers for dimension arrange.\n");
while(scanf("%d %d",&r,&c)!=2)
{
printf("wrong value,do it again.\n");
while(getchar()!='\n')
;
}
double a[r][c];
input(r,c,a);
averageperarray(r,c,a);
greatest(r,c,a);
return 0;
}
void input(int i,int j,double(*p)[j])
{
printf("please,input the numbers for %d*%d 2D array.\n",i,j);
int k=0;
while(k<i*j)
{
if(scanf("%lf",&p[k/j][k%j])!=1)
{
k=-1
;
printf("wrong number,input the whole array again.\n");
while(getchar()!='\n')
;
}
k++;
}
}
void averageperarray(int i,int j,double(*p)[j])
{
double subtal,total;
int g,h;
for(g=0,total=0;g<i;g++)
{
for(h=0,subtal=0;h<j;h++)
subtal+=p[g][h];
printf("the average array %d is %g.\n",g,subtal/j);
total+=subtal;
}
printf("the average totally is %g.\n",total/(i*j));
}
void greatest(int i,int j,double (*p)[j])
{
int k;
double *t;
t=(double *)p;
for(k=0;k<i*j-1;k++)
t[k+1]=t[k]>t[k+1]?t[k]:t[k+1];
printf("the greatest number is %g",t[k]);
}
基于SSM框架的智能家政保洁预约系统,是一个旨在提高家政保洁服务预约效率和管理水平的平台。该系统通过集成现代信息技术,为家政公司、家政服务人员和消费者提供了一个便捷的在线预约和管理系统。 系统的主要功能包括: 1. **用户管理**:允许消费者注册、登录,并管理他们的个人资料和预约历史。 2. **家政人员管理**:家政服务人员可以注册并更新自己的个人信息、服务类别和服务时间。 3. **服务预约**:消费者可以浏览不同的家政服务选项,选择合适的服务人员,并在线预约服务。 4. **订单管理**:系统支持订单的创建、跟踪和管理,包括订单的确认、完成和评价。 5. **评价系统**:消费者可以在家政服务完成后对服务进行评价,帮助提高服务质量和透明度。 6. **后台管理**:管理员可以管理用户、家政人员信息、服务类别、预约订单以及处理用户反馈。 系统采用Java语言开发,使用MySQL数据库进行数据存储,通过B/S架构实现用户与服务的在线交互。系统设计考虑了不同用户角色的需求,包括管理员、家政服务人员和普通用户,每个角色都有相应的权限和功能。此外,系统还采用了软件组件化、精化体系结构、分离逻辑和数据等方法,以便于未来的系统升级和维护。 智能家政保洁预约系统通过提供一个集中的平台,不仅方便了消费者的预约和管理,也为家政服务人员提供了一个展示和推广自己服务的机会。同时,系统的后台管理功能为家政公司提供了强大的数据支持和决策辅助,有助于提高服务质量和管理效率。该系统的设计与实现,标志着家政保洁服务向现代化和网络化的转型,为管理决策和控制提供保障,是行业发展中的重要里程碑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值