主要内容
两个小demo的实现
Demo 1
输入工资 a元
计算输出这个员工交税后的工资
a<=5000 不交税
5k<a<=8k 超出部分交10%的税
8k<a<=10k 超出8k部分交15%的税,超出5k部分交10%的税
a>10k 超出10k部分交20%的税,超出8k部分交15%的税,超出5k部分交10%的税
#include <stdio.h>
int main(){
int wage = 0; //记录工资
int pay = 0;//税后工资
printf("请输入你的工资:");
scanf("%d",&wage);//scanf中"%d"内不要加其他的东西,&记得取地址
//计算板块
if(wage <= 5000){
pay = wage;
}else if(wage > 5000 && wage <= 8000){
pay = (wage-5000)*0.9 + 5000;
}else if(wage > 8000 && wage <= 10000){
pay = (wage-8000)*0.85+3000*0.9+5000;
}else {
pay = (wage-10000)*0.8+2000*0.85+3000*0.9+5000;
}
printf("到手工资:%d", pay);
return 0;
}
Demo2
要求:输入一个人的年龄,如35,输出“your age is thirty-five”(年龄在1~99之间)
//输入年龄 20
//your age is twenty;
#include <stdio.h>
int age = 0;
//输入年龄 20
//your age is twenty;
int main(){
printf("请输入年龄:");
scanf("%d",&age);//记得scanf取地址&(总会忘)
/*程序分析
age / 10 = 0.2.3.4.5.6...
age % 10 = 1 2 3 4 5....
定义三个数组
1~9 [one two three four ... nine]
10~19 [ten eleven twelve ... nineteen]
20、30、40...90 [twenty thirty forty fifty ... ninety]
*/
//保存个位数 one two 字符串char*
//定义数组 gewei[] ={}
char* gewei[] = {"","one","two","three","four","five","six","seven","eight","nine"};
//保存10-19
char* temp[] = {"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
//保存十位
char* shiwei[] = {"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
char* name;//保存每次取出的字符串 name只是一个变量名 char*是字符串
if(age < 10){
//直接访问个位数数组
//age从1开始
name = gewei[age];
} else if(age >= 10 && age <= 19){
//获取个位数 (重要)
int index = age % 10;
name = temp[index];
}else{
//获取个位数
int ge = age % 10;
//获取十位数
int shi = age /10;
//取出对应的单词 取字符串char*
char* shiString = shiwei[shi-2];//shiString只是一个变量名 char*为定义字符串
char* geString = gewei[ge];
printf("your age is %s-%s\n",shiString,geString);//%s为字符串
//中途程序还未运行完就提前结束
return 0;
}
printf("your age is %s\n",name);
return 0;
}
学习心得
晚上一共做了两个小demo,第一个计算工资的demo感觉勉强还能做出来,但第一遍自己写还是会有一些的错误,比如,scanf("%d",&wage)会错误的写成scanf("%d\n",wage);其次就是编程语句赘余,一个printf("到手工资:%d",pay)反复出现;好在最后都改正了,多余的语句也都删除了。第二个demo对现在的我而言,就比较难了,数组、指针的不熟悉,再加上编程思维不行,就只能默默地听东哥的思路,跟着一步步去做。
总之今晚还是有所收获,学会了数组的定义,简单运用;语句的精简等等。