|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
自己编了一个,运行不了,可是不知道问题,想请老师们指导,谢谢。
#include<stdio.h>
#include<math.h>
long int i,s,c;
scanf("%ld",&i);
if (sqrt(i+100)==s)
{if (sqrt(i+268)==c)
{printf("%ld",i);
}
else
{printf("error");
}
}
else
{printf("error");
}
本帖最后由 jackz007 于 2019-3-4 23:20 编辑
- #include <stdio.h>
- #include <math.h>
- // x + 100 = m ^ 2
- // x + 268 = n ^ 2
- // n ^ 2 - m ^ 2 = 168
- // (n - m)(n + m) = 168
- // a = n - m
- // b = n + m
- main(void)
- {
- int a , b , k , m , n , r , x ;
- r = (int) sqrt(168) + 1 ;
- for(k = 2 ; k < r ; k ++) {
- if(! (168 % k)) {
- a = k ;
- b = 168 / k ;
- if (! ((a + b) % 2)) {
- n = (b + a) / 2 ;
- m = (b - a) / 2 ;
- x = m * m - 100 ;
- if(x > 0) printf("%d\n" , x) ;
-
- }
- }
- }
- }
复制代码
运行实况:
F:\[2019]\00.00.Exercise\C\temp>xxx
1581
261
21
F:\[2019]\00.00.Exercise\C\temp>
|
|