由于这些代码也是我初学时写的代码,故其中的规范程度及简洁程度并不很好(此处我后来写的有可以参考一下->C语言代码规范),但是能很好的接近出初学者的水平,也更有参考价值!排版不易,喜欢就点个赞吧!如有问题,请勿吐槽,欢迎留言互相学习。
第4周编程题在线测试
代码实现:
#include
#include
int main()
{
int a,b,c,d;
printf("Input a/b, c/d:");
scanf("%d/%d,%d/%d",&a,&b,&c,&d);
if(a*d>c*b)
{
printf("%d/%d>%d/%d\n",a,b,c,d);
}
else if(a*d<c*b)
{
printf("%d/%d<%d/%d\n",a,b,c,d);
}
else
printf("%d/%d=%d/%d\n",a,b,c,d);
return 0;
}
代码实现:
#include
#include
#include
int main()
{
double a,c;
int b;
char d;
printf("Input rate, year, capital:");
scanf("%lf,%d,%lf",&a,&b,&c);
printf("Compound interest (Y/N)?");
scanf(" %c",&d);
if (d=='Y'||d=='y')
printf("deposit = %.4f\n",c*pow((1+a),b));
else
printf("deposit = %.4f\n",c*(1+a*b));
return 0;
}
代码实现:
#include
#include
int main()
{
int year;
double capital,rate;
char c;
printf("Input capital, year:");
scanf("%lf,%d",&capital,&year);
if (year==1) rate = 0.0225;
if (year==2) rate = 0.0243;
if (year==3) rate = 0.0270;
if (year==5) rate = 0.0288;
if (year==8) rate = 0.0300;
printf("Compound interest (Y/N)?");
scanf(" %c",&c);
if (year!=1&&year!=2&&year!=3&&year!=5&&year!=8)
{
printf("Error year!\n");
}
else
{
if (c=='Y'||c=='y')
{
printf("rate = %.4f, deposit = %.4f\n",rate,capital*pow((1+rate),year));
}
else if (c=='N'||c=='n')
{
printf("rate = %.4f, deposit = %.4f\n",rate,capital*(1+rate*year));
}
}
return 0;
}
代码实现:
#include
#include
int main()
{
float a,b,compete,standard;
printf("Input percent of A and B:");
scanf("%f%f",&a,&b);
compete=(10*a+6*b),standard=(8*a+b*10);
printf("compete = %.4f\nstandard = %.4f\n",compete,standard);
if (compete>=standard)
printf("The Best Response is compete!");
else printf("The Best Response is standard!");
return 0;
}
第四周练兵区——编程题
代码实现:
#include
#include
int main()
{
int a,b,c;
c=scanf("%d %d",&a,&b);
if (c==2)
printf("a = %d, b = %d\n" ,a,b);
else
printf("Input error!");
return 0;
}
代码实现:
#include
#include
int main()
{
int a,b;
b=scanf("%d",&a);
if (b==1)
{
if (a<=0)
{
printf("Input error!\n");
}
else if (((a%4==0)&&(a%100!=0))||(a%400==0))
{
printf("Yes\n");
}
else
{
printf("No\n");
}
}
else
printf("Input error!\n");
return 0;
}
#include
int main()
{
int score;
char grade;
printf("Please input score:");
scanf("%d", &score);
if (score < 0 || score > 100)
printf("Input error!\n");
else if (score >= 90)
grade = 'A’;
else if (score >= 80)
grade = 'B';
else if (score >= 70)
grade = 'C';
else if (score >= 60)
grade = 'D';
else
grade = 'E';
printf("grade:%c\n", grade);
return 0;
}
代码实现:
#include
#include
int main()
{
int score;
char grade;
printf("Please input score:\n");
scanf("%d",&score);
if (score < 0 || score >100)
{printf("Input error!\n");
}
else if (score >=90)
{grade = 'A';
printf("grade: %c\n",grade);
}
else if (score >=80)
{grade = 'B';
printf("grade: %c\n",grade);
}
else if (score >=70)
{grade = 'C';
printf("grade: %c\n",grade);
}
else if (score >=60)
{grade = 'D';
printf("grade: %c\n",grade);
}
else
{grade = 'E';
printf("grade: %c\n",grade);
}
return 0;
}
代码实现:
#include
#include
int main()
{
char c;
printf("Input simple:\n");
scanf( "%c",&c);
if ((c>='0')&&(c<='9'))
{
printf("It is a digit character.\n");
}
else if (((c>='A')&&(c<='Z'))||((c>='a')&&(c<='z')))
{
printf("It is an English character.\n");
}
else
{
printf("It is other character.\n");
}
return 0;
}
代码实现:
#include
#include
int main()
{
int a;
float b;
scanf("%d,%f",&a,&b);
if ((a<0)||(a>4))
{
printf("Error in Area\n");
printf("Price: 0.00");
}
else if (a==0)
{
printf("Price: %5.2f\n",(float)((int)b*3+10));
}
else if (a==1)
{
printf("Price: %5.2f\n",(float)((int)b*4+10));
}
else if (a==2)
{
printf("Price: %5.2f\n",(float)((int)b*5+15));
}
else if (a==3)
{
printf("Price: %5.2f\n",(float)((int)b*6.5+15));
}
else if (a==4)
{
printf("Price: %5.2f\n",(float)((int)b*10+15));
}
return 0;
}
代码实现:
#include
#include
int main()
{
int a,b,c;
printf("Please input n:\n");
scanf("%d",&a);
b=a/100,c=a%100;
printf("%d,%d\n",b,c);
printf("sum=%d,sub=%d,multi=%d\n",b+c,b-c,b*c);
if(c==0)
{
printf("The second operator is zero!\n");
}
else
{
printf("dev=%.2f,mod=%d\n",(float)b/c,b%c);
}
return 0;
}
代码实现:
#include
#include
int main()
{
float a;
int b;
printf("Input distance and time:");
scanf("%f,%d",&a,&b);
if ((a>=0)&&(a<=3))
printf("fee = %.0f\n",(float)(8+(b/5)*2));
else if ((a>3)&&(a<=10))
printf("fee = %.0f\n",(float)(8+(a-3)*2+(b/5)*2));
else if (a>10)
printf("fee = %.0f\n",(float)(22+(a-10)*3+(b/5)*2));
return 0;
}
代码实现:
#include
#include
int main()
{
int n;
printf("Please enter the number:\n");
scanf("%d",&n);
if ((n>0)&&(n<=9))
{printf("%d: 0-9\n",n);}
else if ((n>=10)&&(n<=99))
{printf("%d: 10-99\n",n);}
else if ((n>=100)&&(n<=999))
{printf("%d: 100-999\n",n);}
else if ((n>=1000)&&(n<=9999))
{printf("%d: 1000-9999\n",n);}
else
{printf("error!\n");}
return 0;
}
代码实现:
#include
#include
#include
int main()
{
float a,b,c,d;
printf("Please enter the coefficients a,b,c:\n");
scanf("%f,%f,%f",&a,&b,&c);
if ((b*b-4*a*c)<0)
{printf("error!\n");}
else
{
d = sqrt(b*b-4*a*c);
printf( "x1=%7.4f, x2=%7.4f\n",(float)(-b+d)/2/a,(-b-d)/2/a);
}
return 0;
}