第一周、程序设计与C语言
1.3第一个程序
1.3 hello
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
1.3你好
#include <stdio.h>
int main()
{
printf("你好!\n");
return 0;
}
1.3calculate
#include <stdio.h>
int main()
{
printf("23+43=%d\n", 23+43);
return 0;
}
1.3change
#include <stdio.h>
int main()
{
int price = 0;
printf("请输入金额(元):");
scanf("%d", &price);
int change = 100 - price;
printf("找您%d元。\n", change);
return 0;
}
第二周、计算
2.1变量
2.1plus 两个数相加
#include <stdio.h>
int main()
{
int a;
int b;
printf("请输入两个整数:");
scanf("%d %d", &a, &b);
printf("%d + %d = %d\n", a, b, a + b);
return 0;
}
2.1 change2 找零
#include <stdio.h>
int main()
{
const int AMOUNT = 100;
int price = 0;
printf("请输入金额(元):");
scanf("%d", &price);
int change = AMOUNT - price;
printf("找您%d元。\n", change);
return 0;
}
2.1 height2
#include <stdio.h>
int main()
{
printf("请分别输入身高的英尺和英寸,"
"如输入\"5 7\"表示5英尺7英寸:");
double foot;
double inch;
scanf("%lf %lf", &foot, &inch);
printf("身高是%f米。\n",
((foot + inch / 12) * 0.3048));
return 0;
}
2.2数据类型
2.2 average 两个数平均数
#include <stdio.h>
int main()
{
int a,b;
scanf("%d %d", &a, &b);
double c = (a+b)/2.0;
printf("%d和%d的平均值=%f\n", a, b, c);
return 0;
}
第三周、判断与循环
3.1判断
3.1 age
/*#include <stdio.h>
int main()
{
const int MINOR = 35;
int age = 0;
printf("请输入你的年龄: ");
scanf("%d", &age);
printf("你的年龄是%d岁。\n", age);
if ( age < MINOR ) {
printf("年轻是美好的,");
}
printf("年龄决定了你的精神世界,好好珍惜吧。\n");
return 0;
}*/
#include<stdio.h>
int main()
{
const int MIN=100;
int age=0;
printf("请在此输入你的年龄:");
scanf("%d",&age);
printf("你输入的年龄是%d岁。\n",age);
if(age<=MIN)
{printf("青春无限好\n");
}
printf("你的年龄决定了你的精神世界,请好好珍惜吧!");
return 0;
}
3.1 change3
/*#include <stdio.h>
int main()
{
// 初始化
int price = 0;
int bill = 0;
// 读入金额和票面
printf("请输入金额:");
scanf("%d", &price);
printf("请输入票面:");
scanf("%d", &bill);
// 计算找零
printf("应该找您:%d\n", bill - price);
return 0;
}*/
#include<stdio.h>
int main()
{
int price=0;
int bill=0;
printf("请您输入消费金额:");
scanf("%d",&price);
printf("请您输入票面金额:");
scanf("%d",&bill);
printf("这是找您的零钱(%d)元,欢迎下次光临!",bill-price);
return 0;
}
3.1 change4
#include <stdio.h>
int main()
{
// 初始化
int price = 0;
int bill = 0;
// 读入金额和票面
printf("请输入金额:");
scanf("%d", &price);
printf("请输入票面:");
scanf("%d", &bill);
// 计算找零
if ( bill >= price ) {
printf("应该找您:%d\n", bill - price);
}
return 0;
}
3.1 change5
/*#include <stdio.h>
int main()
{
// 初始化
int price = 0;
int bill = 0;
// 读入金额和票面
printf("请输入金额:");
scanf("%d", &price);
printf("请输入票面:");
scanf("%d", &bill);
// 计算找零
if ( bill >= price ) {
printf("应该找您:%d\n", bill - price);
} else {
printf("你的钱不够\n");
}
return 0;
}*/
#include <stdio.h>
int main()
{
int bill=0;
int price=0;
printf("请输入金额:");
scanf("%d",&bill);
printf("请输入票面:");
scanf("%d",&price);
if(price>=bill)
{printf("找您(%d)元",price-bill);
}
else{printf("你的钱不够");
}
return 0;
}
3.1interval2
#include <stdio.h>
int main()
{
int hour1, minute1;
int hour2, minute2;
scanf("%d %d", &hour1, &minute1);
scanf("%d %d", &hour2, &minute2);
int ih = hour2 - hour1;
int im = minute2 - minute1;
if ( im <0 ) {
im = 60 + im;
ih --;
}
printf("时间差是%d小时%d分。\n", ih, im);
return 0;
}
3.1 max
/*#include <stdio.h>
int main()
{
int a,b;
printf("请输入两个整数:");
scanf("%d %d", &a, &b);
int max = b;
if ( a > b ) {
max = a;
}
printf("大的那个是%d\n", max);
return 0;
}*/
#include <stdio.h>
int main()
{
int a;
int b;
scanf("%d %d",&a,&b);
int max=0;
if(a>b)
{printf("%d",a);
}
else{printf("%d",b);
}
return 0;
}
3.1 max3
/*#include <stdio.h>
int main()
{
int a,b,c;
scanf("%d %d %d", &a, &b, &c);
int max = 0;
if ( a>b ) {
if ( a>c ) {
max = a;
} else {
max = c;
}
} else {
if ( b>c ) {
max = b;
} else {
max = c;
}
}
printf("The max is %d\n", max);
return 0;
}*/
#include<stdio.h>
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
int max=0;
if(a>b)
{if(a>c){printf("%d",a);}
else{printf("%d",c);}}
else{if(b>c){printf("%d",b);
}else{printf("%d",c);
}
}
return 0;
}
3.1 salary
#include <stdio.h>
int main()
{
const double RATE = 8.25;
const int STANDARD = 40;
double pay = 0.0;
int hours;
printf("请输入工作的小时数: ");
scanf("%d", &hours);
printf("\n");
if (hours > STANDARD)
pay = STANDARD * RATE +
(hours-STANDARD) * (RATE * 1.5);
else
pay = hours * RATE;
printf("应付工资: %f\n", pay);
return 0;
}
3.1 score
#include <stdio.h>
int main()
{
const int PASS=60;
int score;
printf("请输入成绩: ");
scanf("%d", &score);
printf("你输入的成绩是%d.\n", score);
if ( score < PASS )
printf("很遗憾,这个成绩没有及格。");
else {
printf("祝贺你,这个成绩及格了。");
printf("再见\n");
}
return 0;
}