user-0 提问: 求教萌新，萌新依旧不知道自己错在了哪里，代码可以正常运行，但输出结果错误，全为-1

回复:
user: user-1
content: 引用 5 楼 forlorn pedestrian 的回复:[quote=引用 4 楼 自信男孩的回复:][quote=引用 2 楼 forlorn pedestrian 的回复:][quote=引用 1 楼 自信男孩的回复:]#include<stdio.h>  //double fac(int m, int n) double fac(long int m, long int n) {     int i, j, k, l, q, t;     double s;      s = 0;     l = 1;     q = 1;     t = 1;      for (i = 1;i <= m;i++) {         l = l * i;     }     for (j = 1;j <= n;j++) {         q = q * j;     }     for (k = 1;k <= (m - n);k++) {         t = t * k;     }     s = l*1.0 / q / k;   //保证这个运算是double类型的      return s; } int main() {     long int m, n;     //scanf_s("ld ld", &m, &n);     scanf_s("%ld %ld", &m, &n);      if (m < n && m>0 && n > 0) {         printf("0");         return 0;     }     if (m == n && m > 0 && n > 0) {         printf("1");         return 0;     }      if (m > n && m > 0 && n > 0) {         printf("%lf", fac(m, n));         return 0;     }     else         printf("-1");     return 0; } 供参考～      //scanf_s("ld ld", &m, &n);     scanf_s("%ld %ld", &m, &n); 对比一下问题  注意事项： s = l*1.0 / q / k;   //保证这个运算是double类型的   //double fac(int m, int n) double fac(long int m, long int n) 可是我依然运行不对，结果全是-1,所以我想问问我哪错了[/quote] 那把你的测试用例发一下，就是你的测试数据～[/quote] 2 2 4 3[/quote]  请再用我的代码测试一下？我的测试结果是这样的： 2 2 1 4 3 2.000000

user: user-0
content: 引用 4 楼 自信男孩的回复:[quote=引用 2 楼 forlorn pedestrian 的回复:][quote=引用 1 楼 自信男孩的回复:]#include<stdio.h>  //double fac(int m, int n) double fac(long int m, long int n) {     int i, j, k, l, q, t;     double s;      s = 0;     l = 1;     q = 1;     t = 1;      for (i = 1;i <= m;i++) {         l = l * i;     }     for (j = 1;j <= n;j++) {         q = q * j;     }     for (k = 1;k <= (m - n);k++) {         t = t * k;     }     s = l*1.0 / q / k;   //保证这个运算是double类型的      return s; } int main() {     long int m, n;     //scanf_s("ld ld", &m, &n);     scanf_s("%ld %ld", &m, &n);      if (m < n && m>0 && n > 0) {         printf("0");         return 0;     }     if (m == n && m > 0 && n > 0) {         printf("1");         return 0;     }      if (m > n && m > 0 && n > 0) {         printf("%lf", fac(m, n));         return 0;     }     else         printf("-1");     return 0; } 供参考～      //scanf_s("ld ld", &m, &n);     scanf_s("%ld %ld", &m, &n); 对比一下问题  注意事项： s = l*1.0 / q / k;   //保证这个运算是double类型的   //double fac(int m, int n) double fac(long int m, long int n) 可是我依然运行不对，结果全是-1,所以我想问问我哪错了[/quote] 那把你的测试用例发一下，就是你的测试数据～[/quote] 2 2 4 3

user: user-1
content: 引用 2 楼 forlorn pedestrian 的回复:[quote=引用 1 楼 自信男孩的回复:]#include<stdio.h>  //double fac(int m, int n) double fac(long int m, long int n) {     int i, j, k, l, q, t;     double s;      s = 0;     l = 1;     q = 1;     t = 1;      for (i = 1;i <= m;i++) {         l = l * i;     }     for (j = 1;j <= n;j++) {         q = q * j;     }     for (k = 1;k <= (m - n);k++) {         t = t * k;     }     s = l*1.0 / q / k;   //保证这个运算是double类型的      return s; } int main() {     long int m, n;     //scanf_s("ld ld", &m, &n);     scanf_s("%ld %ld", &m, &n);      if (m < n && m>0 && n > 0) {         printf("0");         return 0;     }     if (m == n && m > 0 && n > 0) {         printf("1");         return 0;     }      if (m > n && m > 0 && n > 0) {         printf("%lf", fac(m, n));         return 0;     }     else         printf("-1");     return 0; } 供参考～      //scanf_s("ld ld", &m, &n);     scanf_s("%ld %ld", &m, &n); 对比一下问题  注意事项： s = l*1.0 / q / k;   //保证这个运算是double类型的   //double fac(int m, int n) double fac(long int m, long int n) 可是我依然运行不对，结果全是-1,所以我想问问我哪错了[/quote] 那把你的测试用例发一下，就是你的测试数据～

user: user-2
content: 楼主主函数的逻辑判断有问题，修改如下：int main(int argc, char* argv[]) {     long int m, n;     //scanf_s("ld ld", &m, &n);     scanf_s("%ld %ld", &m, &n);      if(m>0 && n > 0)      {        if (m < n)           {             printf("0\n");             //return 0;  //这句多余           }        if (m == n )           {             printf("1\n");             //return 0;  //这句多余           }        if (m > n )           {             printf("%lf\n", fac(m, n));             //return 0;  //这句多余           }      }     else        printf("-1\n");     system("pause");     return 0; }

user: user-0
content: 引用 1 楼 自信男孩的回复:#include<stdio.h>  //double fac(int m, int n) double fac(long int m, long int n) {     int i, j, k, l, q, t;     double s;      s = 0;     l = 1;     q = 1;     t = 1;      for (i = 1;i <= m;i++) {         l = l * i;     }     for (j = 1;j <= n;j++) {         q = q * j;     }     for (k = 1;k <= (m - n);k++) {         t = t * k;     }     s = l*1.0 / q / k;   //保证这个运算是double类型的      return s; } int main() {     long int m, n;     //scanf_s("ld ld", &m, &n);     scanf_s("%ld %ld", &m, &n);      if (m < n && m>0 && n > 0) {         printf("0");         return 0;     }     if (m == n && m > 0 && n > 0) {         printf("1");         return 0;     }      if (m > n && m > 0 && n > 0) {         printf("%lf", fac(m, n));         return 0;     }     else         printf("-1");     return 0; } 供参考～      //scanf_s("ld ld", &m, &n);     scanf_s("%ld %ld", &m, &n); 对比一下问题  注意事项： s = l*1.0 / q / k;   //保证这个运算是double类型的   //double fac(int m, int n) double fac(long int m, long int n) 可是我依然运行不对，结果全是-1,所以我想问问我哪错了

user: user-1
content: #include<stdio.h>  //double fac(int m, int n) double fac(long int m, long int n) {     int i, j, k, l, q, t;     double s;      s = 0;     l = 1;     q = 1;     t = 1;      for (i = 1;i <= m;i++) {         l = l * i;     }     for (j = 1;j <= n;j++) {         q = q * j;     }     for (k = 1;k <= (m - n);k++) {         t = t * k;     }     s = l*1.0 / q / k;   //保证这个运算是double类型的      return s; } int main() {     long int m, n;     //scanf_s("ld ld", &m, &n);     scanf_s("%ld %ld", &m, &n);      if (m < n && m>0 && n > 0) {         printf("0");         return 0;     }     if (m == n && m > 0 && n > 0) {         printf("1");         return 0;     }      if (m > n && m > 0 && n > 0) {         printf("%lf", fac(m, n));         return 0;     }     else         printf("-1");     return 0; } 供参考～      //scanf_s("ld ld", &m, &n);     scanf_s("%ld %ld", &m, &n); 对比一下问题  注意事项： s = l*1.0 / q / k;   //保证这个运算是double类型的   //double fac(int m, int n) double fac(long int m, long int n)