題中給的例子一定要用自定義函數(shù)嗎,如果是在主函數(shù)中寫這樣為什么會不對
#include<stdio.h>
int main()
{
? ? int n;
? ? int result;
? ? scanf("%d",&n);
? ? if (n<0)
? ? {
? ? ? ? printf("輸出錯誤!\n");
? ? }
? ? else if(n==0||n==1)
? ? ? ? result=1;
? ? else
? ? {
? ? ? ? result=n*(n-1);
? ? ? ? return result;
? ? }
? ? printf("%d的階乘為%d",n,result);
? ? return 0;
}
2015-10-28
你自己設一個n值,按這個流程走一遍就知道為什么不行了。