首先fact函數(shù)返回的是double類型,第一個(gè)參數(shù)是double型的二維指針.所以是
站在用戶的角度思考問題,與客戶深入溝通,找到蒙陰網(wǎng)站設(shè)計(jì)與蒙陰網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名與空間、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋蒙陰地區(qū)。
*c[i] = fact (c,y,z);
因?yàn)閐ouble *c[3];是二維double指針,
c[i]是一個(gè)double一維指針,*c[i]就是double型數(shù)據(jù)。c是二維指針,可以傳過去
1。
#include "stdio.h"
//#define RECURSION 1
#ifdef RECURSION
long fact(int n)
{
if(n1) return 1;
return n*fact(n-1);
}
#else
long fact(int n)
{
long t=1;
for(int i=2;i=n;i++)
t*=i;
return t;
}
#endif
main()
{
long s=0;
for(int i=1;i=10;i++)
s+=fact(i);
printf("%ld\n",s);
}
2。
#include "stdio.h"
bool prime(int n)
{
if(n==1) return false;
for(int i=2;i=n/2;i++)
if(n%i==0) return false;
return true;
}
main()
{
int cnt=0;
int i=3;
while(cnt10)
{
if(prime(i) prime(i+2))
{
printf("(%d,%d)\n",i,i+2);
cnt++;
}
i+=2;
}
}
3。
非遞歸
#include "stdio.h"
void main()
{
int s=0,total=0;
int day=0;
while(s100)
{
if(day%2==0)
{
s+=3;
total+=3;
}
else
{
s-=2;
total+=2;
}
day++;
}
if(s100) total-=(s-100);
printf("total %d days,climb %d metres\n",day,total);
}
遞歸
#include "stdio.h"
struct node{
int day;
int total;
};
struct node f(int dest,int tag)
{
if(tag==0)
{
if(dest=3)
{
struct node temp;
temp.day=1;
temp.total=dest;
return temp;
}
else
{
struct node temp,temp1;
temp1=f(dest-3,1);
temp.day=temp1.day+1;
temp.total=temp1.total+3;
return temp;
}
}
else
{
struct node temp,temp1;
temp1=f(dest+2,0);
temp.day=temp1.day+1;
temp.total=temp1.total+2;
return temp;
}
}
void main()
{
struct node a=f(100,0);
printf("total %d days,climb %d metres\n",a.day,a.total);
}
#includestdio.hint fact(int n)。
{int ans=1,i;if(n=1) return 1;for(i=1;i=n; ++i)ans*=i;return ans;}
int main(){int n,ans;scanf("%d",n);ans=fact(n);printf("ans = %d\n",ans);return 0;}
擴(kuò)展資料:
順序結(jié)構(gòu):
順序結(jié)構(gòu)的程序設(shè)計(jì)是最簡單的,只要按照解決問題的順序?qū)懗鱿鄳?yīng)的語句就行,它的執(zhí)行順序是自上而下,依次執(zhí)行。
例如:a = 3,b = 5,現(xiàn)交換a,b的值,這個(gè)問題就好像交換兩個(gè)杯子里面的水,這當(dāng)然要用到第三個(gè)杯子,假如第三個(gè)杯子是c,那么正確的程序?yàn)椋篶 = a; a = b; b = c;執(zhí)行結(jié)果是a = 5,b = c = 3如果改變其順序。
寫成:a = b; c = a; b =c;則執(zhí)行結(jié)果就變成a = b = c = 5,不能達(dá)到預(yù)期的目的,初學(xué)者最容易犯這種錯誤。順序結(jié)構(gòu)可以獨(dú)立使用構(gòu)成一個(gè)簡單的完整程序,常見的輸入、計(jì)算、輸出三步曲的程序就是順序結(jié)構(gòu),例如計(jì)算圓的面積。
其程序的語句順序就是輸入圓的半徑r,計(jì)算s = 3.14159*r*r,輸出圓的面積s。不過大多數(shù)情況下順序結(jié)構(gòu)都是作為程序的一部分,與其它結(jié)構(gòu)一起構(gòu)成一個(gè)復(fù)雜的程序,例如分支結(jié)構(gòu)中的復(fù)合語句、循環(huán)結(jié)構(gòu)中的循環(huán)體等。
參考資料來源:百度百科-c語言
#include stdio.h
main()
{
int a,b,c,d=1;
scanf("%d",a);
printf("Please enter n:");
for(b=1;b=a;b++)
{
for(c=1;c=b;c++)
{
d=d*c;
}
printf("%d! = %ld\n",b,d);
d=1;
}
}
1、打開VC6.0軟件,新建一個(gè)C語言的項(xiàng)目:
2、接下來編寫主程序,首先定義用來求階乘的遞歸函數(shù)以及主函數(shù)。在main函數(shù)里定義變量sum求和,調(diào)用遞歸函數(shù)fact(),并將返回值賦予sum,最后使用printf打印sum的結(jié)果,主程序就編寫完了:
3、最后運(yùn)行程序,觀察輸出的結(jié)果。以上就是C語言使用遞歸求階乘的寫法:
當(dāng)前文章:c語言調(diào)用fact函數(shù) c語音中調(diào)用函數(shù)
文章URL:http://jinyejixie.com/article2/dossdoc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、建站公司、網(wǎng)站改版、域名注冊、網(wǎng)站收錄、營銷型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)