哪个大神帮我做一下这个C语言程序设计题??

2024-11-26 15:40:12
推荐回答(3个)
回答1:

1、
#include
int fun1(int *xx,int n);
int fun2(int *xx,int n);
float fun3(int *xx,int n);
int main()
{
int i,cnt1,cnt2,xx[200];
float pj;

for(i=0;i<200;i++)
scanf("%d",&xx[i]);
cnt1=fun1(xx,200);
cnt2=fun2(xx,200);
pj=fun3(xx,200);
printf("cnt1=%d\ncnt2=%d\npj=%.2f\n",cnt1,cnt2,pj);
return 0;
}
int fun1(int *xx,int n)
{
int i,cnt1=0;

for(i=0;i if(xx[i]%2==1)
cnt1++;
return cnt1;
}
int fun2(int *xx,int n)
{
int i,cnt2=0;

for(i=0;i if(xx[i]%2==1)
cnt2++;
return cnt2;
}
float fun3(int *xx,int n)
{
int i,sum=0;
float pj;

for(i=0;i sum+=xx[i];
pj=1.0*sum/n;
return pj;
}

2、
#include
void countvalue(int *a, int *n);
int main()
{
int i,n,a[300];

countvalue(a,&n);
for(i=0;i {
printf("%5d",a[i]);
if(i%5==0)
printf("\n");
}
printf("\nn=%d\n",n);
return 0;
}
void countvalue(int *a, int *n)
{
int i,j=0;

for(i=1;i<1000;i++)
{
if((i%7==0&&i%11!=0)||(i%11==0&&i%7!=0))
{
a[j]=i;
j++;
}
}
*n=j;
}

回答2:

您好,这样:
#include
#include
#define N 5
struct stu
{
int num;
char name[6];
int scores[3];
};
main()
{
int i,j;
double sum[N]={0};
struct stu Node[N],Node2[N];
FILE *fp;
fp=fopen("1.txt","w");//写入
for(i=0;i {
printf("请输入第%d个人的编号和姓名:\n",i+1);
scanf("%d",&Node[i].num);
scanf("%s",Node[i].name);
printf("请输入第%d个人三门课成绩:\n",i+1);
for(j=0;j<3;j++)
{
scanf("%d",&Node[i].scores[j]);
sum[i]+=Node[i].scores[j];
}
sum[i]/=3;//求平均分
fprintf(fp,"%d %s %d %d %d %lf\n",Node[i].num,Node[i].name,Node[i].scores[0],Node[i].scores[1],Node[i].scores[2],sum[i]);
}
fclose(fp);

fp=fopen("1.txt","r");
for(i=0;i {
fscanf(fp,"%d%s%d%d%d%lf\n",&Node2[i].num,Node2[i].name,&Node2[i].scores[0],&Node2[i].scores[1],&Node2[i].scores[2],&sum[i]);
printf("%d %s %d %d %d %lf\n",Node2[i].num,Node2[i].name,Node2[i].scores[0],Node2[i].scores[1],Node2[i].scores[2],sum[i]);
}
}

回答3:

加分做第2个