毕达哥拉斯定理在C

  • 本文关键字:定理 毕达哥拉斯 c
  • 更新时间 :
  • 英文 :


我做错了什么?

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
double pythagoras (double x, double y);
int x[] = {3,3,1, -1, -1, 1, -3, 0, 6};
int y[] = {4, -4, 1,1,-1,-1,0,4,9};
{
double z;
for(int i = 0; i<sizeof(x)/sizeof(int); i++)
{
z = pythagoras(x[i],y[i]);
z = sqrt(double pow(x,2) + double pow(y,2));
printf("%3d, %3d, %9.5fn" , x[i] ,y[i] , z);
}
printf("%3d, %3d, %9.5fn" , 5,12,pythagoras(5,12) );
return 0;
}
}

试着这样定义pythagoras函数。。。

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
double pythagoras(int,int); //Function Declaration
int main(){
int x[] = {3,3,1,-1,-1,1,-3,0,6};
int y[] = {4,-4,1,1,-1,-1,0,4,9};
double z;
for(int i=0; i<sizeof(x)/sizeof(int); i++){
z = pythagoras(x[i],y[i]); // Function Call
printf("%3d, %3d, %9.5fn", x[i], y[i], z);
}
printf("%3d, %3d, %9.5fn", 5, 12, pythagoras(5,12)); //Function Call
return 0;
}
//Function Definition
double pythagoras(int x, int y){
return sqrt(pow(x,2) + pow(y,2));
}

最新更新