由于这些代码也是我初学时写的代码,故其中的规范程度及简洁程度并不很好(此处我后来写的有可以参考一下->C语言代码规范),但是能很好的接近出初学者的水平,也更有参考价值!排版不易,喜欢就点个赞吧!如有问题,请勿吐槽,欢迎留言互相学习。
第5周编程题在线测试
代码实现:
#include
int main()
{
int a,b,c;
printf("Man Women Children\n");
for (a=0;a<=28;a++)
for (b=0;b<=28;b++)
for (c=0;c<=28;c++)
if(a+b+c==30&&a*3+b*2+c==50)
printf("%3d%8d%8d\n",a,b,c);
return 0;
}
代码实现:
#include
#include
int main()
{
int a,b,c,d,x1,x2,x3,x4,x5,x6,x7,x8,x9,x0;
for(a=22;a>=10;a--)
{
b=a*a*a;
x1=b/1000,x2=(b%1000)/100,x3=(b%100)/10,x4=b%10;
c=a*a*a*a;
if(c>=100000 && c<=999999)
{x5=c/100000,x6=(c%100000)/10000,x7=(c%10000)/1000,x8=(c%1000)/100,x9=(c%100)/10,x0=c%10;}
if(x1!=x2&&x1!=x3&&x1!=x4&&x1!=x5&&x1!=x6&&x1!=x7&&x1!=x8&&x1!=x9&&x1!=x0&&x2!=x3&&x2!=x4&&x2!=x5&&x2!=x6&&x2!=x7&&x2!=x8&&x2!=x9&&x2!=x0&&x3!=x4)
{
printf("age=%d\n",a-1);
goto END;
}
}
END: ;
return 0;
}
代码实现:
#include
int main()
{
int a,b,c,d,e,f;
printf("Input your birth year:");
scanf("%d",&a);
printf("Input this year:");
scanf("%d",&b);
c=a/4,d=b/4,e=0;
if(c*4==a)
{
e=c*4,f=0;
while(e<=b)
{printf("%d\n",e);
e=e+4;
f++;
}}
else
{
e=c*4+4,f=0;
while(e<=b)
{printf("%d\n",e);
e=e+4;
f++;
}}
printf("count=%d\n",f);
return 0;
}
代码实现:
#include
int isleap(int n)//判断闰年
{
if((n%4 == 0 && n%100 != 0)||(n%400 == 0)) return 1;
else return 0;
}
int main()
{
int day1 = 365,day2 = 366;
int begin,end,number;
long unsigned int count = 0;
printf("Input your birth year:");
scanf("%d",&begin);
printf("Input this year:");
scanf("%d",&end);
for(;begin < end;begin++){
number = isleap(begin)?day2:day1;
count += number*24*60*75;
}
printf("The heart beats in your life: %lu",count);
return 0;
}
第五周练兵区——编程题
代码实现:
#include
#include
#include
int main()
{
int a,b,c,d,x0,x1,x2,x3,x4,x5,x6,x7,x8,x9;
x0=x1=x2=x3=x4=x5=x6=x7=x8=x9=0;
printf("Please enter the number:\n");
scanf("%d",&a);
b = fabs(a);
c=1;
do
{
c++;
d = b%10;
b = b/10;
switch(d)
{
case 0 :
x0++;
break;
case 1 :
x1++;
break;
case 2 :
x2++;
break;
case 3 :
x3++;
break;
case 4 :
x4++;
break;
case 5 :
x5++;
break;
case 6 :
x6++;
break;
case 7 :
x7++;
break;
case 8 :
x8++;
break;
case 9 :
x9++;
break;
}
}while(b/10!=0&&b>=10);
switch(b)
{case 0 :
x0++;
break;
case 1 :
x1++;
break;
case 2 :
x2++;
break;
case 3 :
x3++;
break;
case 4 :
x4++;
break;
case 5 :
x5++;
break;
case 6 :
x6++;
break;
case 7 :
x7++;
break;
case 8 :
x8++;
break;
case 9 :
x9++;
break;
}
printf("%d: %d bits\n",a,c);
if (x0>0)
printf("0: %d\n",x0);
if (x1>0)
printf("1: %d\n",x1);
if (x2>0)
printf("2: %d\n",x2);
if (x3>0)
printf("3: %d\n",x3);
if (x4>0)
printf("4: %d\n",x4);
if (x5>0)
printf("5: %d\n",x5);
if (x6>0)
printf("6: %d\n",x6);
if (x7>0)
printf("7: %d\n",x7);
if (x8>0)
printf("8: %d\n",x8);
if (x9>0)
printf("9: %d\n",x9);
return 0;
}
代码实现:
#include
#include
int main()
{
long int a,b;
scanf("%ld",&a);
if (a<=100000)
b=a*0.1;
else if(a<=200000)
b=10000+(a-100000)*0.075;
else if(a<=400000)
b=17500+(a-200000)*0.05;
else if(a<=600000)
b=27500+(a-400000)*0.03;
else if(a<=1000000)
b=33500+(a-600000)*0.015;
else
b=39500+(a-1000000)*0.01;
printf("bonus=%ld\n",b);
return 0;
}
#include
int main()
{
int i, j, sum = 0, n=100;
for (i=1,j=n; i<=j; i++,j--)
{
sum = sum + i + j;
}
printf("sum = %d", sum);
return 0;
}
代码实现:
#include
int main()
{
int i, j, sum = 0, n;
scanf("%d",&n);
for (i=1; i<=n; i++)
{
sum = sum + i;
}
printf("sum = %d", sum);
return 0;
}
#include
int main()
{
int sum = 0, m;
do{
printf("Input m:\n");
scanf("%d", &m);
sum = sum + m;
printf("sum = %d\n", sum);
}while (m != 0);
return 0;
}
代码实现:
#include
#include
int main()
{
int m=1,sum=0;
while(m!=0)
{
printf("Input m:\n");
scanf("%d",&m);
sum+=m;
if(m==0) break;
printf( "sum = %d\n",sum);
}
return 0;
}
#include
int main()
{
int x, y, z;
for (x=0; x<=20; x++)
{
for (y=0; y<=33; y++)
{
z = 100 - x - y;
if (5*x + 3*y + z/3 == 100)
{
printf("x=%d, y=%d, z=%d\n", x, y, z);
}
}
}
return 0;
}
代码实现:
#include
int main()
{
int x, y, z;
for (x=0; x<=20; x++)
{
for (y=0; y<=33; y++)
{
z = 100 - x - y;
if (5*x + 3*y + z/3 == 100 && z%3==0)
{
printf("x=%d, y=%d, z=%d\n", x, y, z);
}
}
}
return 0;
}
#include
#include
int main()
{
int n, i;
printf("Input n:\n");
scanf("%d", &n);
for (i=2; i<=sqrt(n); i++)
{
if (n % i = 0)
{
printf("No!\n");
}
}
printf("Yes!\n");
return 0;
}
代码实现:
#include
#include
int main()
{
int n, i;
printf("Input n:\n");
scanf("%d", &n);
if (n==0 || n==1 || n<0)
printf("No!\n");
else
{
for (i=2; i<n; i++)
{
if (n % i == 0)
{
printf("No!\n");
exit(0);
}
}
printf("Yes!\n");
}
return 0;
}
#include
int main()
{
int x1, x2;
do{
printf("Input x1, x2:");
scanf("%d,%d", &x1, &x2);
}while (x1 * x2 > 0);
printf("x1=%d,x2=%d\n", x1, x2);
return 0;
}
代码实现:
#include
#include
#include
int main()
{
int x1, x2, n, flag;
do
{
flag = 0;
printf("Input x1, x2:\n");
n = scanf("%d,%d", &x1, &x2);
switch (n)
{
case 0:
while (getchar() != '\n');
flag = 1;
break;
case 1:
while (getchar() != '\n');
flag = 1;
break;
default:
if (x1 * x2 >= 0)
flag = 1;
else
flag = 0;
break;
}
}
while (flag == 1);
printf("x1=%d,x2=%d\n", x1, x2);
return 0;
}
代码实现:
#include
#include
int main()
{
int a,b,c=1;
printf("Input days:\n");
scanf("%d",&a);
for(b=2;b<=a;a--)
c=(c+1)*2;
printf("x=%d\n",c);
return 0;
}
代码实现:
#include
#include
int main()
{
int a,b,c=1,d,e;
printf("Input days:\n");
scanf("%d",&a);
do
{
d=1;
printf("Input days:\n");
e = scanf("%d",&a);
switch(e)
{
case 0:
while(getchar()!='\n')
d=1;
break;
case 1:
for(b=2;b<=a;a--)
c=(c+1)*2;
break;
}
} while(a<=0);
printf("x=%d\n",c);
return 0;
}
代码实现:
#include
#include
int main()
{
int a,d,b,c,e;
d=0,a=c=1,e=0;
printf("Input your password:\n");
do
{
b=scanf("%d",&a);
switch (b)
{case 0:
printf("error\n");
getchar();
c=1;
break;
case 1:
d++;
printf("%d, you have enter %d-bits number\n",a,d);
c=0;
break;
}
e++;
}while(c==1||e<=7);
return 0;
}
代码实现:
#include
#include
#include
int main()
{
int a,b,c,d,x0,x1,x2,x3,x4,x5,x6,x7,x8,x9;
x0=x1=x2=x3=x4=x5=x6=x7=x8=x9=0;
printf("Please enter the number:\n");
scanf("%d",&a);
b = fabs(a);
c=1;
do
{
c++;
d = b%10;
b = b/10;
}while(b/10!=0&&b>=10);
printf("%d: %d bits\n",a,c);
}
代码实现:
#include
int main()
{
int a,b,c;
printf("Please enter the number:\n");
b=c=0;
scanf("%d",&a);
if(a!=-1)
{
while(a!=-1)
{
if(a!=-1)
{if(a%2==0)
{printf("%d:even\n",a);
b++;
}
else
{printf("%d:odd\n",a);
c++;
}
}
else
break;
scanf("%d",&a);
}}
else
{
printf("over!\n");
}
printf("The total number of odd is %d\n",c);
printf("The total number of even is %d\n",b);
return 0;
}
代码实现:
#include
#include
#include
int main()
{
int a,b;
float c=100,d=100,e=100;
printf("Input:\n");
scanf("%d",&a);
for(b=1;b<a;b++)
{
e=e/2;
c=c+e;}
printf("%d times:\n",a);
printf("%.3f\n",c*2-100);
d=pow(0.5,a)*d;
printf("%.3f\n",d);
return 0;
}