简单C语言程序的例子
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
例子:
#include
main ()
{
tips(); /*caller*/
printf(“\n Success is about banging on after others have let go”);
}
tips() /*caller*/
{
printf (“\n When you reach the end of the rope tie a knot & hang on”,)0; }
[上述程序的输出结果如下:
When you reach the end of the ropt tie a knot & hang on.
Success is about hanging on after others have let go.]
#include
main()
{
int a,fact;
printf(“\nEnter any number”);
scanf(“%d”,&a);
fact=rec(a);
printf(“Factorial value is%d”,fact);
}
rec(x);
int x;
{
int f;
if(x==1)
return(1);
else
f=x*rec(x-1);
return(f);
}
[其显示的结果为:Factorial value is 2.]
比较两个数较大的那个:
#include
main()
{
int a,b,max;
scanf (“%d%d”,&a,&b);
if (a>b)
max=a;
else max=b;
printf (“%d”,max);
}
输出a+b的值:
#include
void main()
{
int a,b,x;
scanf (“%d%d”,&a,&b);
x=a+b;
printf (“%d”,x);
}
输出a,b中最大的一位数:
#include
int max(int x,int y)
{
int z;
if (x>y) z=x;
else z=y;
return(z);
}
void main()
{
int a,b,c;
scanf (“%d%d”,&a,&b);
c=max(a,b);
printf (“%d\n”,c);
}
输出Hello:
#include
int main()
{
printf (“Hello!”);
return 0;
}
求1~100的和:
#include
int main()
{
int s,n;
s=0,n=1;
A: s=s+n;
n=n+1;
if (n<=100)
goto A;
printf (“%d”,s);}
请输入一个三位数,将其各位逆序输出:(如153,输出351)
#include
void main()
{
int x,y,a,b,c;
printf ("请输入一个三位数的数:");
scanf("%d",&x);
a=x/100;
b=x%100/10;
c=x%10;
y=c*100+b*10+a;
printf ("\n%d",y);
}
#include
void main()
{
int x,a,b,c,d;
printf ("请输入一个三位数的数:");
scanf("%d",&x);
a=x/100;
b=x%100/10;
c=x%10;
d=c*100+b*10+a;
printf ("\n%d\n",d);
}
买鸡:
#include
void main()
{
int x,y,z;
if(x>=0&&x<=19,y>=0&&y<=33,z>=0&&z<=100) while (x=19)
{
x=0;
5*x+3*y+z/3==100&&x+y+z==100;
x=x+1;
}
printf("%d%d%d",x,y,z);
}
y==(100-5*x-z/3)/3&&y==100-x-z;
z==(100-5*x-3*y)*3&&z==100-x-y;
#include
void main()
{
int x=0,y,z;
while (x<=19)
{
5*x+3*y+z/3==100&&x+y+z==100;
x=x+1;
printf("%d%d%d",x,y,z);
}
}
#include
void main()
{
int x=0,y=0,z=0;
while (x<=19)
{
while (y<=33)
{
while (z<=100)
{