在使用一個函數(shù)之前必須先對他進(jìn)行聲明:

目前成都創(chuàng)新互聯(lián)已為千余家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)絡(luò)空間、成都網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計、鎮(zhèn)遠(yuǎn)網(wǎng)站維護(hù)等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
//void B();聲明B函數(shù)的存在。void A(){B();//非法,程序執(zhí)行到此時并不知道B函數(shù)的存在。}void B(){}
或者
#include stdio.h
#include stdlib.h
#include math.h
int fa(int n)
{
int a;
for(a=2;a=sqrt(n*1.0),n%a!=0;a++);
if(asqrt(n*1.0))
return(1);
else
return(0);
}
void main( )
{
int n,q;
scanf("%d",n);
擴(kuò)展資料
#include stdio.h
#include stdlib.h
#include math.h
int fa(int n)
{
int a;
for(a=2;a=sqrt(n*1.0),n%a!=0;a++);
if(asqrt(n*1.0))
return(1);
else
return(0);
}
void main( )
{
int n,q;
scanf("%d",n);
if(fa(n)==1)
printf("n");
else
printf("y");
system("pause");
exit(0);
}
參考資料:百度百科 - C語言函數(shù)
可以的,前提是,在使用一個函數(shù)之前必須先對他進(jìn)行聲明:
//void B();聲明B函數(shù)的存在。
void A()
{
B();//非法,程序執(zhí)行到此時并不知道B函數(shù)的存在。
}
void B()
{
}
或者
#include stdio.h
#include stdlib.h
#include math.h
int fa(int n)
{
int a;
for(a=2;a=sqrt(n*1.0),n%a!=0;a++);
if(asqrt(n*1.0))
return(1);
else
return(0);
}
void main( )
{
int n,q;
scanf("%d",n);
擴(kuò)展資料
從函數(shù)定義的角度看,函數(shù)可分為庫函數(shù)和用戶定義函數(shù)兩種。
(1)庫函數(shù)
由C系統(tǒng)提供,用戶無須定義, 也不必在程序中作類型說明,只需在程序前包含有該函數(shù)原型的頭文件即可在程序中直接調(diào)用。在前面各章的例題中反復(fù)用到printf 、 scanf 、 getchar 、putchar、gets、puts、strcat等函數(shù)均屬此類。
(2)用戶定義函數(shù)
由用戶按需要寫的函數(shù)。對于用戶自定義函數(shù), 不僅要在程序中定義函數(shù)本身, 而且在主調(diào)函數(shù)模塊中還必須對該被調(diào)函數(shù)進(jìn)行類型說明,然后才能使用。
#include
#include
void
add(float
x,float
y)
//函數(shù)定義
{
printf("%5.2f\n",x+y);//計算a+b
}
main()
{float
a=0.0,b=0.0;
double
s;
scanf("%f,%f",a,b);//輸入a
b
add(a,b);//直接調(diào)用函數(shù)
s=sqrt(a);
printf("跟號a=%f\n",s);
s=sqrt(b);
printf("跟號b=%f\n",s);
}
問題補充:
你的想法很好,可以的話去學(xué)下C++吧,能學(xué)到你所想的
你想調(diào)用函數(shù)的話,把這函數(shù)做成一個C文件,以后需要時就合并用吧
在C中函數(shù)是不可以嵌套定義的,也就是說
在main函數(shù)里寫自定義函數(shù)
這種說法是錯誤的,你只能在Main外面定義,在Main中調(diào)用
比如:
int
max(int
a,int
b)
{if
(ab)
return
a;else
return
b;}
main()
{
printf("%d\n",max(3,7));
}
寫個程序你看看就知道了,題目:求兩個整數(shù)中的大者.程序如下:#include"stdio.h"int main(void){ int max(int x,int y); //函數(shù)聲明 int a b c; //定義變量 scanf(”%d,%d“,a,b); //輸入兩個數(shù) c=max(a,b); //調(diào)用max函數(shù)。將得到的值賦給c printf("%d\n",c); //輸出c的值}int max(int x,int y) //函數(shù)定義部分。定義max函數(shù)為整型。函數(shù)值為整型,形式參數(shù)x,y為整型,{ int z; //max函數(shù)的聲明部分 if(xy) z=x; else z=y; return(z);}后面的那一句語句就是自定義的,是前面需要調(diào)用的函數(shù)。在c中,不管你把main函數(shù)放在前面還是后面都是從main函數(shù)開始執(zhí)行的。
新聞標(biāo)題:c語言怎么嵌入自定義函數(shù),c語言自定義函數(shù)怎么用
瀏覽路徑:http://chinadenli.net/article12/hedegc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、網(wǎng)頁設(shè)計公司、Google、網(wǎng)站設(shè)計、手機(jī)網(wǎng)站建設(shè)、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)