C常用函数源码范例Word文档格式.docx
《C常用函数源码范例Word文档格式.docx》由会员分享,可在线阅读,更多相关《C常用函数源码范例Word文档格式.docx(28页珍藏版)》请在冰豆网上搜索。
![C常用函数源码范例Word文档格式.docx](https://file1.bdocx.com/fileroot1/2023-1/10/03b36845-66ea-48eb-a6ee-c37b055abe85/03b36845-66ea-48eb-a6ee-c37b055abe851.gif)
printf("
\n"
}
return0;
}
//*do_while函数
#include<
inti;
printf("
inputanumber:
"
scanf("
%d"
&
i);
do
%d\n"
i++);
}while(i<
10);
END!
//*do_while
(1)函数
intn;
n=0;
scanf("
n);
}while((n<
0)||(n>
100));
n*n=%d\n"
n*n);
—————————————————————————————————————————
//*for_if嵌套
inti,j=0,m,k,n;
inputaint:
"
for(m=3;
m<
=n;
m++)
k=0;
for(i=2;
=m-1;
if(m%i==0)
{
k=1;
break;
}
if(k==0)
printf("
%3d"
m);
j+=1;
if(j%4==0)
//*for_if嵌套1
for(i=2;
=9;
if(i==7)
break;
for(j=2;
if(j==5)
%dx%d=%2d"
j,i,j*i);
//*for_if嵌套2
if(i==5)
continue;
continue;
//*FOR函数
inti,sum=0;
=100;
sum+=i;
sum);
//*FOR函数1
chara;
for(;
printf("
input:
),scanf("
a),a!
='
\t'
;
\nthecharis:
%c\n"
a);
a=NULL;
//*FOR函数2
inti,j,k;
2;
3;
for(k=0;
k<
4;
k++)
i=%d,j=%d,k=%d\n"
i,j,k);
//*FOR函数3
inti,j,k,n;
pleaseinputaint:
for(i=1;
for(j=1;
=40-i;
for(k=1;
=2*i-1;
*"
//*FOR函数4
inth,m,s;
for(h=0;
h<
24;
h++)
for(m=0;
60;
for(s=0;
s<
s++)
printf("
%d:
%d\r"
h,m,s);
//*getchar()
voidfoo1(void);
voidfoo2(void);
voidfoo1(void)
foo1\n"
voidfoo2(void)
foo2\n"
void(*ptr)(void);
getchar();
ptr=foo1;
ptr();
ptr=foo2;
//*getchar
(1)
intfoo(void);
intfoo(void)
return
(1);
foo()=%d\n"
foo());
foo=%d\n"
foo);
//*if—gooto函数
inti=1,sum=100;
loop:
sum+=i;
i++;
if(i<
100)
gotoloop;
else
//*IF函数
pleaseinputanumber:
if(i==0)
thisnumberis0\n"
thisnumberisnot0,itis%d\n"
i);
//*IF函数1
inta,b,x,y;
pleaseinputa:
a);
pleaseinputb:
b);
if(a>
=b)
x=a;
y=b;
x=b;
y=a;
x=%d,y=%d\n"
x,y);
//*IF函数2
intnum;
chargrade;
100~90:
A,89~75:
B,74~60:
C,59~0:
D\n"
pleaseinputyournumber:
num);
if((num>
=0)&
&
(num<
=100))
if(num>
89)
grade='
A'
elseif(num>
74)
B'
59)
C'
else
D'
yournumber:
%d,is:
num,grade);
numbererror!
//*IF函数3
inta,b,c,max;
pleaseinputa,b,c:
%d,%d,%d"
a,&
b,&
c);
b)
if(a>
c)
max=a;
if(b>
max=b;
max=c;
ina,b,cmax=%d"
max);
//*scanf对非法字符的处理
//scanf对非法字符的处理
intmain(viod)
charch;
while
(1)
请输入一个数:
i=%d\n"
while((ch=getchar())!
='
\n'
)//清空上一次输入的数据
continue;
j);
j=%d\n\n"
j);
//*static函数
voidrun(void);
voidrun(void)
staticintx=1;
x+=2;
x=%d\n"
x);
clrscr();
run();
//*strcpy函数
string.h>
charstrscr[80],strdes[80];
inputstring:
%s"
strscr);
strcpy(strdes,strscr);
copystring:
%s\n"
strdes);
//*strlen与sizeof函数
unsignedcharstr_zh[80];
inputstr_zh:
str_zh);
str_zh:
strlen(str_zh));
sizeof(str_zh));
//*SWITCH函数
charselect;
\n(a)100~90\n"
(b)89~75\n"
(c)74~60\n"
(d)59~0\n"
pleaseinputachar:
select);
switch(select)
case'
a'
:
100~90\n"
break;
b'
89~75\n"
c'
74~60\n"
d'
59~0\n"
default:
error\n"
//*SWITCH函数2
case'
//*while函数
while(i<
10)
//*函数参数
charinputchar(void);
voidoutput(char);
charinputchar(void)
inputachar:
ch);
return(ch);
voidoutput(chara)
thecharis:
%c"
output(inputchar());
//*函数调用
intx;
voida(void);
voida(void)
intx=20;
input:
x);
a();
//*函数调用
(2)
voidx20(void);
voidx30(void);
voidx20(void)
x=20;
voidx30(void)
x=30;
x20();
x30();
//*函数调用及参数
voida_1(intb);
voida_1(intb)
a*a=%d\n"
b*b);
inta;
a_1(a);
//*函数调用及参数2
inta_1(intb);
inta_1(intb)
intc;
c=b*b;
return(c);
a_1(a));
//*逆输出应用
chararg[80],*p;
arg);
p=arg;
for(i=strlen(arg);
=strlen(arg);
i--)
p[i]);
//*数组输出及指针应用
int