error C2664: 'ave' : cannot convert parameter 1 from 'int [4][5]' to 'int *请问错在哪里?
#include<stdio.h>#include<stdlib.h>intmain(){inti,j;floatlv;voidprint(int*p[],intx,in...
#include<stdio.h>
#include<stdlib.h>
int main ()
{ int i,j;float lv;
void print(int *p[],int x,int y);
float ave(int *a[],int n);
int a[4][5];
for(i=0;i<4;i++)
{ printf("第%d个学生的5个成绩:\n",i+1);
for(j=0;j<5;j++)
scanf("%d",&a[i][j]);
}
printf("%f",lv=ave(a,4));
printf("\n");
print(a,4,5);
return 0;
}
float ave(int *a[],int n)
{ int i,sum=0;float lv;
for(i=0;i<n;i++)
sum+=*a[i];
return lv=1.0*sum/n;
}
void print(int p[][5],int x,int y)
{ int i,j,k,sum;
for(i=0;i<x;i++)
{ k=0,sum=0;
for(j=0;j<y;j++)
{ if(*(p[i]+j)<60)
k++;
if(k>=2)
{
printf("学号是%d\n",i+1);
for(k=0;k<y;k++)
{ printf("%d ",*(p[i]+k));
sum+=*(p[i]+k);
}
printf("\n");
printf("平均数是%f\n",1.0*sum/y);
break;
}
}
}
}
--------------------Configuration: Cpp0703 - Win32 Debug--------------------
Compiling...
Cpp0703.cpp
C:\Users\Administrator\Documents\vc++\Cpp0703.cpp(13) : error C2664: 'ave' : cannot convert parameter 1 from 'int [4][5]' to 'int *[]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Users\Administrator\Documents\vc++\Cpp0703.cpp(15) : error C2664: 'print' : cannot convert parameter 1 from 'int [4][5]' to 'int *[]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Users\Administrator\Documents\vc++\Cpp0703.cpp(23) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
Error executing cl.exe.
Cpp0703.obj - 2 error(s), 1 warning(s) 展开
#include<stdlib.h>
int main ()
{ int i,j;float lv;
void print(int *p[],int x,int y);
float ave(int *a[],int n);
int a[4][5];
for(i=0;i<4;i++)
{ printf("第%d个学生的5个成绩:\n",i+1);
for(j=0;j<5;j++)
scanf("%d",&a[i][j]);
}
printf("%f",lv=ave(a,4));
printf("\n");
print(a,4,5);
return 0;
}
float ave(int *a[],int n)
{ int i,sum=0;float lv;
for(i=0;i<n;i++)
sum+=*a[i];
return lv=1.0*sum/n;
}
void print(int p[][5],int x,int y)
{ int i,j,k,sum;
for(i=0;i<x;i++)
{ k=0,sum=0;
for(j=0;j<y;j++)
{ if(*(p[i]+j)<60)
k++;
if(k>=2)
{
printf("学号是%d\n",i+1);
for(k=0;k<y;k++)
{ printf("%d ",*(p[i]+k));
sum+=*(p[i]+k);
}
printf("\n");
printf("平均数是%f\n",1.0*sum/y);
break;
}
}
}
}
--------------------Configuration: Cpp0703 - Win32 Debug--------------------
Compiling...
Cpp0703.cpp
C:\Users\Administrator\Documents\vc++\Cpp0703.cpp(13) : error C2664: 'ave' : cannot convert parameter 1 from 'int [4][5]' to 'int *[]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Users\Administrator\Documents\vc++\Cpp0703.cpp(15) : error C2664: 'print' : cannot convert parameter 1 from 'int [4][5]' to 'int *[]'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Users\Administrator\Documents\vc++\Cpp0703.cpp(23) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
Error executing cl.exe.
Cpp0703.obj - 2 error(s), 1 warning(s) 展开
1个回答
展开全部
你需要指定二维数组形参的第二维长度。否则没办法寻址
float ave(int *a[5],int n)
void print(int p[][5],int x,int y) // 这个函数是没错的。但你在main函数中的前项声明错了。
#include<stdio.h>
#include<stdlib.h>
int main ()
{ int i,j;float lv;
void print(int *p[],int x,int y); // 这里改成int p[][5]
float ave(int *a[],int n);
int a[4][5];
for(i=0;i<4;i++)
{ printf("第%d个学生的5个成绩:\n",i+1);
for(j=0;j<5;j++)
scanf("%d",&a[i][j]);
}
printf("%f",lv=ave(a,4));
printf("\n");
print(a,4,5);
return 0;
}
float ave(int *a[],int n) // 这里改成int (*a)[5]
{ int i,sum=0;float lv;
for(i=0;i<n;i++)
sum+=*a[i];
return lv=1.0*sum/n;
}
void print(int p[][5],int x,int y)
{ int i,j,k,sum;
for(i=0;i<x;i++)
{ k=0,sum=0;
for(j=0;j<y;j++)
{ if(*(p[i]+j)<60)
k++;
if(k>=2)
{
printf("学号是%d\n",i+1);
for(k=0;k<y;k++)
{ printf("%d ",*(p[i]+k));
sum+=*(p[i]+k);
}
printf("\n");
printf("平均数是%f\n",1.0*sum/y);
break;
}
}
}
}
float ave(int *a[5],int n)
void print(int p[][5],int x,int y) // 这个函数是没错的。但你在main函数中的前项声明错了。
#include<stdio.h>
#include<stdlib.h>
int main ()
{ int i,j;float lv;
void print(int *p[],int x,int y); // 这里改成int p[][5]
float ave(int *a[],int n);
int a[4][5];
for(i=0;i<4;i++)
{ printf("第%d个学生的5个成绩:\n",i+1);
for(j=0;j<5;j++)
scanf("%d",&a[i][j]);
}
printf("%f",lv=ave(a,4));
printf("\n");
print(a,4,5);
return 0;
}
float ave(int *a[],int n) // 这里改成int (*a)[5]
{ int i,sum=0;float lv;
for(i=0;i<n;i++)
sum+=*a[i];
return lv=1.0*sum/n;
}
void print(int p[][5],int x,int y)
{ int i,j,k,sum;
for(i=0;i<x;i++)
{ k=0,sum=0;
for(j=0;j<y;j++)
{ if(*(p[i]+j)<60)
k++;
if(k>=2)
{
printf("学号是%d\n",i+1);
for(k=0;k<y;k++)
{ printf("%d ",*(p[i]+k));
sum+=*(p[i]+k);
}
printf("\n");
printf("平均数是%f\n",1.0*sum/y);
break;
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询