使用函数原型创建程序时,出现了问题。它说:错误:语义问题从不兼容类型'void'分配'int'
Semantic issue Assigning to 'int' from incompatible type 'void'.
能否请你帮我解决这个问题?
这里是我的代码:
#include <stdio.h>
#include <math.h>
void powr(int);
int main(void) {
int n=1, sq, cu, quart, quint;
printf("Integer Square Cube Quartic Quintic\n");
do {
sq = powr(n); //here is the error line
cu = powr(n); //here is the error line
quart = powr(n); //here is the error line
quint = powr(n); //here is the error line
printf("%d %d %d %d %d\n", n, sq, cu, quart, quint);
n++;
}
while (n<=25);
return 0;
}
void powr(int n)
{
int a, cu, quart, quint;
a=pow(n,2);
cu=pow(n,3);
quart=pow(n,4);
quint=pow(n,2);
}
'powr'被定义为void,如果你想以这种方式使用它,原型应该是'int powr(int n)' – amdixon
@amdixon和下一个4个返回值的问题。 :) –
不知道用户在这里做什么。真的应该使用像sq = pow(n,2); ... quint = pow(n,5)这样的std数学函数pow。 – amdixon