算法竞赛入门经典 1.5 实验题目上机

//1.5 小结与习题
//数据类型实验(C++)
//实验A1:表达式11111*11111的值是多少?把5个1改成6个1呢?9个1呢?
#include<iostream>
using namespace std;

int main()
{
	cout<<11111*11111<<endl;		//5个1在范围内,结果为123454321
	cout<<111111*111111<<endl;		//6个1整型常量溢出
	cout<<111111111*111111111<<endl;//整型常量溢出,编译出错
	return 0;
}

//实验A2:把实验A1中的所有数换成浮点数,结果如何
#include<iostream>
using namespace std;

int main()
{
	cout<<11111.0*11111.0<<endl;		//结果为:1.23454e+008
	cout<<111111.0*111111.0<<endl;		//结果为:1.23457e+010
	cout<<111111111.0*111111111.0<<endl;//结果为:1.23457e+016
	return 0;
}

//实验A3:表达式sqrt(-10)的值是多少?尝试用各种方式输出。在计算过程中系统会报错吗?
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
	double a=sqrt(-10.0);	//sqrt函数返回一个double型数值
	cout<<sqrt(-10.0)<<endl;//输出结果:-1.#IND
	cout<<a<<endl;
	return 0;
}

//实验A4:表达式1.0/0.0,0.0/0.0的值是多少?尝试用各种方式输出。在计算过程中会报错吗?
#include<iostream>
using namespace std;

int main()
{
	double a,b;
	a=1.0/0.0;
	b=0.0/0.0;
	cout<<a<<" "<<b<<endl;			//出错:被零除或对零求模
	cout<<1.0/0.0<<" "<<0.0/0.0<<endl;//出错:被零除或对零求模
	return 0;
}

//实验A5:表达式1/0的值是多少?在计算过程会报错吗?
#include<iostream>
using namespace std;

int main()
{
	cout<<1/0<<endl;  //报错:被零除或对零求模
	return 0;
}


//1.5.2 scanf输入格式实验(C语言)
//实验B1:在同一行中输入12和2,是否得到了预期的结果?
#include<stdio.h>

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);	//输入a,b
	printf("%d%d",a,b);		//连续输出
	printf("%d %d",a,b);	//间隔输出
	return 0;
}

	
//实验B2:在不同的两行中输入12和2,是否得到了预期的结果?
#include<stdio.h>

int main()
{
	int a,b;
	scanf("%d\n%d\n",&a,&b);
	printf("%d%d",a,b);
	printf("%d %d",a,b);
	return 0;

}

//实验B3:在实验B1和B2中,在12和2前面和后面加入大量的空格或水平制表符,甚至插入一些空行
#include<stdio.h>

int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d%d\n",a,b);	//连续输出
	printf("%d %d\n",a,b);	//输出两个数之间空一格
	printf("%d\t%d\n",a,b); //输出空一个水平制表符
	return 0;

}

//实验B4:把2换成字符s,重复实验B1~B3
#include<stdio.h>

int main()
{
	int a=12;
	char b='s';
	printf("%d%c\n",a,b);
	printf("%d %c\n",a,b);
	printf("%d\t%c\n",a,b);
	return 0;

}


//1.53 printf语句输出实验
//实验C1:仅用一条printf语句,打印1+2和3+4的值,用两个空行隔开
#include<stdio.h>

int main()
{
	printf("%d\n\n%d\n",1+2,3+4);
	return 0;

}


//实验C2:试着把%d中的两个字符(百分号和小写字母d)输出到屏幕
#include<stdio.h>

int main()
{
	printf("%c %c",'%','d');
	return 0;

}

//实验C3:试着把\n中的两个字符(反斜线和小写字母n)输出到屏幕

#include<stdio.h>

int main()
{
	printf("%c %c",'\\','n');
	return 0;

}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小巫技术博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值