假如有一函數(shù)f, 沒有參數(shù), 則要這樣調(diào)用:
成都創(chuàng)新互聯(lián)是一家專注于網(wǎng)站設(shè)計、網(wǎng)站制作與策劃設(shè)計,陽西網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計領(lǐng)域的專業(yè)建站公司;建站業(yè)務涵蓋:陽西等地區(qū)。陽西做網(wǎng)站價格咨詢:13518219792
f();
其中, f是函數(shù)f的函數(shù)名, 但對于編譯器來講, f是一個地址, 它指向了f函數(shù)代碼段的開頭部分.而()是一個運算符, 它非常類似于*, 但是*是取值的, 而()是讓程序跳轉(zhuǎn)到f處執(zhí)行程序. 最后的那個分號就是標識著一個語句的結(jié)束
如果f有一個整型的參數(shù), 那么需要這樣調(diào)用:
f(1);
只是多了一個1, 這個1就是()運算符要復制到f函數(shù)的棧中了, 準確地說是復制到它的形參中.
如果f有多個參數(shù), 則只需要在每個形參之間打上逗號:
f(1, 2, 3);
逗號只是用來起分隔作用.
#include"stdio.h"
#include"string.h"
struct?account
{
char?name[20];
int?money;
}accounts;
void?plm()
{?
printf("您賬戶的余額:%d",accounts.money);
}
void?qwe()
{
int?cunkuan;??
printf("請輸入存款金額:");?
scanf("%d",cunkuan);?
accounts.money=cunkuan+accounts.money;
printf("???存款成功!\n賬戶余額:%d\n",accounts.money);
}
void?poi()
{?
int?qukuan,i;
printf("請輸入取款金額:");
while(1)
{
scanf("%d",qukuan);?
if(accounts.moneyqukuan)
{?
printf("賬戶余額不足!你的賬戶余額:%d\n請重新輸入:",accounts.money);?
}
else?
{
accounts.money=accounts.money-qukuan;
printf("取款成功!\n賬戶余額:%d\n",accounts.money);
break;
}?
}
}
void?main()
{
char?name[20];?
char?mima[20];?
int?q;
printf("====================================================\n");?
printf("====================================================\n");
printf("==================歡迎你使用銀行系統(tǒng)================\n");
printf("====================================================\n");?
printf("====================================================\n\n");
printf("請輸入你的賬戶名:");?
gets(name);
printf("請輸入密碼:");
gets(mima);
printf("\n");
if(strcmp(name,"zengxin")==0strcmp(mima,"12345")==0)
{?
printf("登陸成功!\n");
int?t=1;
while(t)//主函數(shù)加上一個while循環(huán)就好了,t表示是否繼續(xù)使用系統(tǒng),選擇0時,t=1,即可退出系統(tǒng)了
{
printf("???1?存款???2?取款??3?開戶\n");?
printf("???4?銷戶???5?查詢??0?退出\n請選擇:");?
scanf("%d",q);?
switch?(q)?
{?
case?1:
{
qwe();
break;
}?
case?2:
{
poi();
break;
}?
case?3:
break;?
case?4:
break;??
case?5:
{
plm();
break;
}?????
case?0:
{
t=0;
break;
}
}?
}
}
else?
printf("輸入的賬戶名和密碼錯誤?。?);
可以啦,他說會死循環(huán)是因為他沒控制好?。『瘮?shù)調(diào)用自己本身的確就叫遞歸,main一樣可以遞歸,不過比較少用!遞歸就要控制好條件,有退出的條件,不能永遠執(zhí)行,那沒意義,只要控制好條件就行了!`#include stdio.hvoid main(void)
{
static i=0; printf("%d\n",i); i++;
if (i3)
{
main();
}
}
在使用一個函數(shù)之前必須先對他進行聲明:
//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);
擴展資料
#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ù)
新聞名稱:c語言在主函數(shù)調(diào)用函數(shù) c語言主函數(shù)怎么調(diào)用函數(shù)
文章來源:http://muchs.cn/article30/hgssso.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、微信小程序、搜索引擎優(yōu)化、Google、面包屑導航、外貿(mào)建站
聲明:本網(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)