由于这些代码也是我初学时写的代码,故其中的规范程度及简洁程度并不很好(此处我后来写的有可以参考一下->C语言代码规范),但是能很好的接近出初学者的水平,也更有参考价值!排版不易,喜欢就点个赞吧!如有问题,请勿吐槽,欢迎留言互相学习。
第3周编程题在线测试
代码实现:
#include
#include
int main()
{
int math1, English, math2;
printf("Input math1, English and math2:");
scanf("%d,%d,%d", &math1, &English, &math2);
printf("Final score = %.2f\n", (math1*5+English*1.5+math2*3.5)/10);
return 0;
}
代码实现:
#include
#include
#include
int main()
{
int days;
float length;
printf("Input length and days:");
scanf("%f,%d", &length, &days);
length = pow(0.5, days) * length;
printf("length=%.5f\n", length);
return 0;
}
代码实现:
#include
#include
int main()
{
float p, price;
printf("Input payment p:");
scanf("%f", &p);
price = 0.92 * p;
printf("price = %.1f\n", price);
return 0;
}
代码实现:
#include
int main()
{
int h1,h2,m1,m2,s,t1,t2;
printf("Input time one(hour, minute):");
scanf("%d,%d",&h1,&m1);
printf("Input time two(hour, minute):");
scanf("%d,%d",&h2,&m2);
s=(h1*60+m1)-(h2*60+m2);
if(s<0)
s=-s;
t1=s/60;
t2=s%60;
printf("%d hour %d minute\n",t1,t2);
return 0;
}
第三周练兵区——编程题
代码实现:
#include
#include
int main()
{
int mm, dd, yy ;
printf("Enter a date (mm/dd/yy):\n");
scanf("%d/%d/%d", &mm, &dd, &yy);
printf("You entered the date: %04d.%02d.%02d\n", yy, mm, dd);
return 0;
}
代码实现:
#include
#include
int main()
{
int number, date, mm, dd, yy;
float price;
printf("Enter item number:\n");
scanf("%d", &number);
printf("Enter unit price:\n");
scanf("%f", &price);
printf("Enter purchase date (mm/dd/yy):\n");
scanf("%d/%d/%d", &mm, &dd, &yy);
printf("Item Unit Purchase\n");
printf("%-9d$ %-9.2f%02d%02d%04d\n", number, price, mm, dd, yy);
return 0;
}
代码实现:
#include
#include
#include
int main()
{
float x, y, c1, c2, c;
printf("Please input x and y:\n");
scanf("%f,%f", &x, &y);
c1 = pow(x, 2);
c2 = pow(y, 2);
c = c1 +c 2;
printf("Result=%.2f\n", c);
return 0;
}
代码实现:
#include
#include
#include
int main()
{
int x, y, a, b, c, d, e;
printf("Input x:\n");
scanf("%d", &x);
x = fabs(x);
a=x/1000,b=(x%1000)/100,c=(x%100)/10,d=x%10;
y=d*1000+c*100+b*10+a;
printf("y=%d\n",y);
printf("a=%d,b=%d\n",d*10+c,b*10+a);
e = pow((d*10+c),2)+pow((b*10+a),2);
printf("result=%d\n",e);
return 0;
}
代码实现:
#include
#include
int main()
{
char a,b,c;
printf("Input your English name:\n");
scanf("%c%c%c",&a,&b,&c);
a=a-32;
printf("%c%c%c\n",a,b,c);
a=a+32;
printf("%c:%d\n",a,a-96);
printf("%c:%d\n",b,b-96);
printf("%c:%d\n",c,c-96);
return 0;
}
代码实现:
#include
#include
#include
int main()
{
int a,b;
float t,c;
printf("Input weight, height:\n");
scanf("%d,%d",&a,&b);
printf("weight=%d\n",2*a);
c=(float)b/100;
printf("height=%.2f\n",c);
t=a/(pow(c,2));
printf("t=%.2f\n",t);
return 0;
}