1、
#include <stdio.h> int fac(int x) { if(x > 0) return x * fac(x - 1); else return 1; } int main(void) { int a, b; puts("please input two integers."); printf("a = "); scanf("%d", &a); printf("b = "); scanf("%d", &b); printf("result: %d\n", fac(a)/(fac(b)*fac(a - b))); return 0; }
2、
#include <stdio.h> int fac(int x) { if(x > 0) return x * fac(x - 1); else return 1; } int main(void) { int a, b; puts("please input two integers."); do { printf("a = "); scanf("%d", &a); if(a < 0) { puts("the range of a >= 0."); continue; } printf("b = "); scanf("%d", &b); if(b < 0) { puts("the range of b >= 0."); continue; } if(a < b) puts("a should >= b."); } while( a < b || a < 0 || b < 0); puts("==========\n"); printf("the result: %d\n", fac(a)/(fac(b) * fac(a - b))); return 0; }