主函数
#include <stdio.h>
#include <math.h> int main() { int i,t; float a[3],b[3]; printf("The possible perfect squares combinations are:\n"); for(i=11; i<=31; i++) for(t=11; t<=31; t++) { f(i*i,a); f(t*t,b); if(sqrt(a[0]*10+b[0])==(int)sqrt(a[0]*10+b[0])&&sqrt(a[1]*10+b[1])==(int)sqrt(a[1]*10+b[1])&&sqrt(a[2]*10+b[2])==(int)sqrt(a[2]*10+b[2])) printf("%d and %d\n",i*i,t*t); } return 0;}
调用函数
void f(int n,float *s) { int k; for(k=1000; k>=10; s++) { *s=(n%k)/(k/10); k/=10; } }
[root@localhost ad23]# vim sqrt.c [root@localhost ad23]# vim f.c [root@localhost ad23]# gcc sqrt.c f.c -lm [root@localhost ad23]# ls a.out f.c sqrt.c [root@localhost ad23]# ./a.out The possible perfect squares combinations are: 400 and 900 841 and 196