菜鸟入门
例一
/*功能:输入数字1——7,输出对应星期*/
#include<stdio.h>
void again()
{
int a;
printf("input integer numbers:");
scanf_s("%d", &a);
switch (a)
{
case 1:printf("周1\n"); break;
case 2:printf("周2\n"); break;
case 3:printf("周3\n"); break;
case 4:printf("周4\n"); break;
case 5:printf("周5\n"); break;
case 6:printf("周6\n"); break;
case 7:printf("周7\n"); break;
default:printf("error!\n");
}
}
void main()
{
while(1)
{
again();
}
}
例二
/*代码实现解简单应用题*/
/*初学C语言,有不足还请指正*/
/*用switch开关语句对运输公司成本进行计算*/
/* 基本运费p,货物重量w,距离s,折扣d,总运费f,f=p*w*s*d 要求:s<250 KM 没有折扣
250<=s<500 2%
500<=s<1000 5%
1000<=s<2000 8%
2000<=s<3000 10%
s>=3000
*/
#include<stdio.h>
int son()
{
int p = 0, w = 0, s = 0, a = 0;
double d = 0;
double f = 0;
printf("货物重量w(t):\n");
scanf_s("%d", &w);
printf("基本运费p(t):\n");
scanf_s("%d", &p);
printf("请键入路程s(kil):\n");
scanf_s("%d", &s);
if (s < 250)
{
d = 1;
s = 1;
}
if (s >= 250 && s < 500)
{
d = 0.98;
s = 2;
}
if (s >= 500 && s < 1000)
{
d = 0.95;
s = 3;
}
if (s >= 1000 && s < 2000)
{
d = 0.92;
s = 4;
}
if (s >= 2000 && s < 3000)
{
d = 0.9;
s = 5;
}
if (s >= 3000)
{
d = 0.85;
s = 6;
}
switch (s)
{
case 1:printf("总运费为:%f\n___________________________________\n", p * w * s * d); break;
case 2:printf("总运费为:%f\n___________________________________\n", p * w * s * d); break;
case 3:printf("总运费为:%f\n___________________________________\n", p * w * s * d); break;
case 4:printf("总运费为:%f\n___________________________________\n", p * w * s * d); break;
case 5:printf("总运费为:%f\n___________________________________\n", p * w * s * d); break;
case 6:printf("总运费为:%f\n___________________________________\n", p * w * s * d); break;
}
return 0;
}
int main()
{
while (1)
{
son();
}
}