经典算法--C语言代码大全
/*韩信点兵*/
#include\{
int i=900;
for(i=900;i<=1100;i=i++) if(i%3==1&&i%5==1&&i%7==1) { printf(\满足条件的值为:%d\\n\break; } }
/*两个日期之间的天数*/ #include \{
int i,y,m1,m2,d1,d2; int d=0;
printf(\请输入年月日:\\n如2010年1月3日和3月4日输入格式为2010 1 3 3 4\\n\
scanf(\y=(y%4==0&&y0!=0||y@0==0)?1:0; for(i=m1;i case 1: case 3: case 5: case 7: case 8: case 10: case 12: d+=31; break; case 4: case 6: case 9: case 11: d+=30; break; case 2: d=d+28+y; break; } printf(\} /* N 乘方表*/ #include\void main() { int n,i,p=1; printf(\请输入n的值,按回车键确定~\\n\scanf(\do { i=p*p; printf(\的乘方为%.0d\\n\p=p++; }while(p<=n); } /* 判断某一日期是当年的第几天*/ #include\void main() { int n,year,month,day,month_day_sum=0,sum, month_day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; printf(\请输入\\\年月日\\\scanf(\ if(year0!=0&&year%4==0||year@0==0) month_day[2]=29; if(day>31||day<1||month>12||month<1) printf(\错误\else { for(n=1;n sum=month_day_sum+day; printf(\是%d年的第%d天\\n\} } /*n的阶乘表*/ #include\void main() { float n, i=1,p=1; printf(\请输入n的值:\\n\scanf(\do { i=i*p; if(p<=15) printf(\的阶乘为%.2f\\n\else printf(\的阶乘为%4.5e\\n\p=p++; }while(p<=n); } /*求一元二次方程的解*/ #include\#include\ void main() { int m; do { m=1; float a,b,c,delta,x1,x2,realpt,imagpt; printf(\本程序可求一元二次方程的解。\\n\printf(\请输入一元二次方程的三个参数。\\n\scanf(\if(a!=0) { delta=b*b-4*a*c; if(delta>0) { x1=(-b+sqrt(delta)/2*a); x2=(+b+sqrt(delta)/2*a); printf(\方程的两个不等实根为:x1=%8.4f x2=%8.4f\\n\} else if(delta==0) { x1=x2=-b/(2*b); printf(\方程的两个相等实根为:x1=x2=%8.4f\\n\}