简单易懂的C语言源代码(供初学者使用)

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include

main()

{float pi=3.14159265,r;

printf("enter radius:\n");

scanf("%f",&r);

printf("r=%.2f,c=%.2f,area=%.2f\n",r,2*pi*r,pi*r*r);

system("pause");

}

#include

main()

{int m,n,x,y;

printf("inputm,n:\n");

scanf("%d%d",&m,&n);

if (n%2==1)

{printf("error!! n bu shi ji shu!\n",n);

return;}

/*n在这里不能是奇数*/

x=(4*m-n)/2;

y=(n-2*m)/2;

if((x>=0)&&(y>=0))

printf("x=%d,y=%d\n",x,y);

else

printf("shu ru cuo wu!\n");

getch();

}

#include

#include

#include

main()

{float a,b,C;

printf("enter 3number(a,b,C):\n"); scanf("%.2f %.2f %.2f",&a,&b,&C); s=0.5*a*b*sinC;

printf("s=%.2f\n",s);

system("pause");

}

#include

main()

{int ds,nl,yf;

char c;

printf("shu ru ds;\n");

scanf("%d",&ds);

if (ds<14||ds>1184)

{printf("input error!press any end...\n");

scanf("%c",&c);

exit(0);

}

/*输入的数字必须是-14~1184之间*/

nl=(ds+115)%100;

yf=(ds+115)/100;

printf("nl=%d,yf=%d\n",nl,yf);

system("pause");}

#include

#include

main()

{char s1[100],s2[100],s3[100],s4[100];

printf("input a string:\n");

gets(s1);

strcpy(s1,s2);

strcat(s1,"--------------");

strcpy(s3,strcat(s1,"--------------"));

strcat(strcpy(s3,strcat(s1,"--------------")),s2);

strcpy(s4,strcat(strcpy(s3,strcat(s1,"--------------")),s2)); puts(s4);

system("pasue");

getch();

}

#include

#include

main()

{float x1,x2,a,b,c;

printf("input 3 number(a,b,c):\n"); scanf("%f%f%f",&a,&b,&c);

x1=(-b+sqrt(b*b-4*a*c))/(2*a);

x2=(-b-sqrt(b*b-4*a*c))/(2*a); printf("x1=%f,X2=%f\n",x1,x2); system("pause");

getch();

}

#include

main()

{int a,b,c,t;

printf("input 3 number:\n");

scanf("%d%d%d",&a,&b,&c);

if(a>b)

{t=a;a=b,b=t;}

if(a>c)

{t=a;a=c;c=t;}

if(b>c)

{t=b;b=c;c=t;}

printf("1:%d,2:%d,3:%d\n",a,b,c);

system("pause");

}

#include

#include

#include

main()

{float pi=3.14159265,r;

textbackground(YELLOW);/* 设置背景色为黄色,注意颜色应该大写,可更改 */ textcolor(RED); /* 设置文件颜色为红色,可更改 */

clrscr(); /* 清屏,使设置生效 */

printf("enter radius:");

scanf("%f",&r);

if(r<0)

printf("Enter Error!\n");

else

printf("r=%.2f,c=%.2f,area=%.2f\n",r,2*pi*r,pi*r*r);

相关文档
最新文档