栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

程序设计入门——C语言【课堂练习】

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

程序设计入门——C语言【课堂练习】

第一周、程序设计与C语言 1.3第一个程序

1.3 hello

#include 

int main()
{
    printf("Hello World!n");

    return 0;
}

1.3你好

#include 

int main()
{
    printf("你好!n");

    return 0;
}

1.3calculate

#include 

int main()
{
    printf("23+43=%dn", 23+43);

    return 0;
}

1.3change

#include 

int main()
{
    int price = 0;

    printf("请输入金额(元):");
    scanf("%d", &price);

    int change = 100 - price;

    printf("找您%d元。n", change);

    return 0;
}
第二周、计算 2.1变量

2.1plus 两个数相加

#include 

int main()
{
	int a;
	int b;

	printf("请输入两个整数:");
	scanf("%d %d", &a, &b);
	printf("%d + %d = %dn", a, b, a + b);

	return 0;
}

2.1 change2 找零

#include 

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 

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 

int main()
{
	int a,b;

	scanf("%d %d", &a, &b);

	double c = (a+b)/2.0;
	
	printf("%d和%d的平均值=%fn", a, b, c);

	return 0;
}
第三周、判断与循环 3.1判断

3.1 age

#include
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
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 

int main()
{
	//	初始化
	int price = 0;
	int bill = 0;
	//	读入金额和票面
	printf("请输入金额:");
	scanf("%d", &price);
	printf("请输入票面:");
	scanf("%d", &bill);
	//	计算找零
	if ( bill >= price ) {
		printf("应该找您:%dn", bill - price);
	}

	return 0;
}

3.1 change5

 
#include 
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 

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 

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
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 

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("应付工资: %fn", pay);

	return 0;
}

3.1 score

#include 

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;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/853949.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号