请帮我上0和负数时,为什么结果老是1???
#include<stdio.h>float x(int);
main()
{
int a;
printf("请输入一个数:");
scanf("%d",&a);
printf("\n%d!是:%f",a,x(a));
}
float x(b)
{
float s=1,a=1;
if (b<0)
b=-b;
if(b=0)
s=0;
while (a<=b)
{
s=s*a;
a++;
}
return s;
}
#include<stdio.h> int x(int b); int main(void) { int a; printf("enter"); scanf("%d",&a); if(a<=0) { printf ("Error!\n"); return 1; } printf("\n%d!is%i\n",a,x(a)); return 0; } int x(int b) { int s=1,a=1; while(a<=b) { s=s*a; a++; } return s; }