IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> 《C语言程序设计现代方法:第2版 修订版》第五章课后编程题 -> 正文阅读

[C++知识库]《C语言程序设计现代方法:第2版 修订版》第五章课后编程题

《C语言程序设计现代方法:第2版 修订版》第五章课后编程题,水平有限,仅供参考。
1

#include <stdio.h>

int main (void)
{
    int number;

    printf("Enter a number:");
    scanf("%d",&number);

    if (100<=number&&number<=999)
        printf("The number %d have 3 digits",number);
    else if(10<=number&&number<=99)
        printf("The number %d have 2 digits",number);
    else
        printf("The number %d have 1 digit",number);

    return 0;     
}

2

#include <stdio.h>

int main (void)
{
	int hour,time;
	
	printf("Enter a 24-hour time:");
	scanf("%d:%d",&hour,&time);
		
	if(hour>12){
		printf("Equivalent 12-hour time: %d:%d PM",hour-12,time);
	}
	else{
		printf("Equivalent 12-hour time: %d:%d AM",hour,time);
	}
	
	return 0;
}

3

#include <stdio.h>

int main (void)
{
	float commission,value,pre_price,num,oppose;
	
	printf("Please enter price of each shar:");
	scanf("%f",&pre_price);
	printf("Please enter the number of your share:");
	scanf("%f",&num);
	
	value=pre_price*num;
	
	if(num<2000){
		oppose=0.33*num+0.03;
	}
	else if(num>2000){
		oppose=0.33*num+0.02;
	}
	if(value<2500.00f)
		commission=30.00f+.017f*value;
	else if(value<6250.00f)
		commission=56.00f+.0066f*value;
	else if(value<20000.00f)
		commission=76.00f+.0034f*value;
	else if(value<50000.00f)
		commission=100.00f+.0022f*value;
	else if(value<500000.00f)
		commission=155.00f+.0011f*value;
	else
		commission=255.00f+.0009f*value;
	
	if(commission<39.00f)
		commission=39.00f;
		
	printf("Commission:$%.2f\n",commission);
	printf("Opponent:$%.2f\n",oppose);
	
	return 0;
}

4

#include <stdio.h>

int main (void)
{
	float speed;
	
	printf("Please enter the speed:");
	scanf("%f",&speed);
	
	if(speed<1){
		printf("It's Calm.");
	}
	else if(speed>=1&&speed<=3){
		printf("It's Light air.");
	}
	else if(speed>=4&&speed<=27){
		printf("It's Breeze.");
	}
	else if(speed>=28&&speed<=47){
		printf("It's Gale.");
	}
	else if(speed>=48&&speed<=63){
		printf("It's Storm.");
	}
	else{
		printf("It's Hurricane.");
	}
	
	return 0;
}

5

#include <stdio.h>

int main (void)
{
	float earning,tax;
	
	printf("Please enter the number of your earning:");
	scanf("%f",&earning);
	
	if(earning<=750){
		tax=earning*0.01;
	}
	else if(earning>=750&&earning<=2250){
		tax=7.5+(earning-750)*0.02;
	}
	else if(earning>=2250&&earning<=3750){
		tax=37.5+(earning-2250)*0.03;
	}
	else if(earning>=3750&&earning<=5250){
		tax=82.5+(earning-3750)*0.04;
	}
	else if(earning>=5250&&earning<=7000){
		tax=142.5+(earning-5250)*0.05;
	}
	else{
		tax=230+(earning-7000)*0.06;
	}
	
	printf("The tax you should pay is %f",tax);
	
	return 0;
}

6

#include <stdio.h>

int main (void)
{
	int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11,i12,first_sum,second_sum,total;
	
	printf("Enter the first 11 digits of a UPC: ");
	scanf("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d",&i1,&i2,&i3,&i4,&i5,&i6,&i7,&i8,&i9,&i10,&i11,&i12);
	
	first_sum=i1+i3+i5+i7+i9+i11;
	second_sum=i2+i4+i6+i8+i10;
	total=3*first_sum+second_sum;
	
	if((9-((total-1)%10))==i12){
		printf("VALID");
	}
	else{
		printf("NOT VALID");
	}
	
	return 0;
}

7

#include <stdio.h>

int main (void)
{
	int num1,num2,num3,num4;
	int min1,max1,min2,max2;
	//分成两组,两两做比 
	 
	printf("Enter four integers:");
	scanf("%d %d %d %d",&num1,&num2,&num3,&num4);
	
	if(num1>num2){
		max1=num1;
		min1=num2; 
	}
	else{
		max1=num2;
		min1=num1;
	}//num1<num2
	
	if(num3>num4){
		max2=num3;
		min2=num4; 
	}
	else{
		max2=num4;
		min2=num3;
	}//num3<num4
	
	if(min1<min2)min2=min1;
	if(max1<max2)max1=max2;
	
	printf("Lagest:%d\n",max1);
	printf("Smallest:%d",min2);
	
	return 0;
}

8

#include <stdio.h>

int main (void)
{
	int hour,time,compare;
	
	printf("Enter a 24-hour time:");
	scanf("%d:%d",&hour,&time);
	
	compare=hour*60+time;
	
	if(compare<=8*60+51.5){
		printf("Cloest departure time is 8:00 a.m,arrivint at 10:16 a.m.");
	}
	else if(compare>=8*60+51.5&&compare<=9*60+43+48){
		printf("Cloest departure time is 9:43 a.m,arrivint at 11:52 a.m.");
	}
	else if(compare>=9*60+43+48&&compare<=11*60+19+44){
		printf("Cloest departure time is 11:19 a.m,arrivint at 13:31 p.m.");
	}
	else if(compare>=11*60+19+44&&compare<=12*60+47+36.5){
		printf("Cloest departure time is 12:47 p.m,arrivint at 15:00 p.m.");
	}
	else if(compare>=12*60+47+36.5&&compare<=14*60+52.5){
		printf("Cloest departure time is 14:00 p.m,arrivint at 16:08 a.m.");
	}
	else if(compare>=14*60+52.5&&compare<=15*60+45+97.5){
		printf("Cloest departure time is 15:45 p.m,arrivint at 17:55 p.m.");
	}
	else if(compare>=15*60+45+97.5&&compare<=19*60+82.5){
		printf("Cloest departure time is 19:00 p.m,arrivint at 21:20 p.m.");
	}
	else{
		printf("Cloest departure time is 21:45 p.m,arrivint at 23:58 p.m.");
	}
}

9

#include <stdio.h>

int main (void)
{
	int day1,month1,year1,day2,month2,year2;
	
	printf("Enter first date (mm/dd/yy):");
	scanf("%d/%d/%d",&month1,&day1,&year1);
	printf("Enter second date (mm/dd/yy):");
	scanf("%d/%d/%d",&month2,&day2,&year2);
	
	if(year2<year1){
		printf("%d/%d/%d is earlier than %d/%d/%d",month2,day2,year2,month1,day1,year1);
	}
	else if(year2==year1){
		if(month2<month1){
			printf("%d/%d/%d is earlier than %d/%d/%d",month2,day2,year2,month1,day1,year1);
		}
		else if(month2==month1){
			if(day2<day1){
				printf("%d/%d/%d is earlier than %d/%d/%d",month2,day2,year2,month1,day1,year1);
			}
			else if (day2>day1){
				printf("%d/%d/%d is earlier than %d/%d/%d",month1,day1,year1,month2,day2,year2);
			}
		}
		else{
			printf("%d/%d/%d is earlier than %d/%d/%d",month1,day1,year1,month2,day2,year2);
		}
	}
	else{
		printf("%d/%d/%d is earlier than %d/%d/%d",month1,day1,year1,month2,day2,year2);
	}
	
	return 0;
}

10

#include <stdio.h>

int main (void)
{
	int number,grade;
	
	printf("Enter numerical grade:");
	scanf("%d",&number);
		
	if(number>100||number<0){
		printf("Error!");
	}
	else{
		grade=number/10;
		switch (grade){
			case 10:printf("Letter grade: A");break;
			case 9:printf("Letter grade: A");break;
			case 8:printf("Letter grade: B");break;
			case 7:printf("Letter grade: C");break;
			case 6:printf("Letter grade: D");break;
			default:printf("Letter grade: F");break;
		}
	}
	
	return 0;
}

11

#include <stdio.h>

int main (void)
{
	int number,tens,ones;
	
	printf("Enter a two-digit number:");
	scanf("%d",&number);
	
	tens=number/10;
	ones=number%10;
	
	if(tens==1){
		switch(ones){
				case 1:printf("You entered the number:eleven.");break;
				case 2:printf("You entered the number:twelve.");break;
				case 3:printf("You entered the number:thirteen.");break;
				case 4:printf("You entered the number:fourteen.");break;
				case 5:printf("You entered the number:fifteen.");break;
				case 6:printf("You entered the number:sixteen.");break;
				case 7:printf("You entered the number:seventeen.");break;
				case 8:printf("You entered the number:eighteen.");break;
				case 9:printf("You entered the number:nineteen.");break;
					}
				}
	else{
		switch(tens){
		case 2:printf("You entered the number twenty-");break;
		case 3:printf("You entered the number thirty-");break;
		case 4:printf("You entered the number fourty-");break;
		case 5:printf("You entered the number fifty-");break;
		case 6:printf("You entered the number sixty-");break;
		case 7:printf("You entered the number seventy-");break;
		case 8:printf("You entered the number eighty-");break;
		case 9:printf("You entered the number ninety-");break;
					}
		switch(ones){
		case 1:printf("one.");break;
		case 2:printf("two.");break;
		case 3:printf("three.");break;
		case 4:printf("four.");break;
		case 5:printf("five.");break;
		case 6:printf("six.");break;
		case 7:printf("seven.");break;
		case 8:printf("eight.");break;
		case 9:printf("nine.");break;
					}
		}
	
	return 0;
}
  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2022-02-01 20:25:11  更:2022-02-01 20:26:04 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 8:33:03-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码