- 2
- 0
- 约1.78千字
- 约 3页
- 2018-05-26 发布于河南
- 举报
c第5章习题讲解
5-2
#include iostream
using namespace std;
//#include math.h
int main()
{
int i,j,min,temp,a[11];
cout请输入10个整数endl;
for (i=1;i=10;i++)
{
couta[i]=;
cina[i]; //输入10个数
}
coutendl初始的数组序列为:endl;;
for (i=1;i=10;i++)
couta[i] ; // 输出这10个数
coutendl;;
for (i=1;i=9;i++) //以下是对10个数排序
{
min=i;
for (j=i+1;j=10;j++)
if (a[min]a[j]) min=j;
temp=a[i]; //以下3行将a[i+1]~a[10]中最小者与a[i] 对换
a[i]=a[min];
a[min]=temp;
}
coutendl排序后的数组序列为:endl;
for (i=1;i=10;i++) // 输出已排好序的10个数
couta[i] ;
coutendl;
return 0;
}
5-4
#include iostream
using namespace std;
int main()
{
int a[11];
int num,i;
cout请输入10个按照升序排列的整数序列endl;
for (i=0;i10;i++)
{
couta[i+1]=;
cina[i]; //输入10个数
}
cout数组a:endl;
for (i=0;i10;i++)
couta[i] ;
coutendl;;
cout请输入要插入的数据:;
cinnum;
if (numa[9])
a[10]=num;
else
{
for (i=9;i=0;i--)
if (a[i]num)
a[i+1]=a[i];
else
break;
a[i+1]=num;
}
cout插入数据后的数组 a:endl;
for (i=0;i11;i++)
couta[i] ;
coutendl;
return 0;
}5-5
#include iostream
using namespace std;
int main()
{
const int n=5;
int a[n], i, temp;
cout请输入”n”个整数:endl;
for (i=0;in;i++)
cina[i];
cout互换前 a:endl;
for (i=0;in;i++)
couta[i] ;
for (i=0;in/2;i++) //循环的作用是将对称的元素的值互换
{
temp=a[i];
a[i]=a[n-1-i];
a[n-i-1]=temp;
}
coutendl互换后数组 a:endl;
for (i=0;in;i++)
couta[i] ;
coutendl;
return 0;
}
5-7
见实验四
5-13
见实验四
您可能关注的文档
- (中国大学生必读文章)总有一天华为会光荣走进美国.docx
- (经营资料汇总表).doc
- (赵老师)学期工作总结.doc
- (一)矿井管理人员安全生产岗位责任制.doc
- (马老师)学期后勤工作总结.doc
- +606m西二石门瓦斯抽放设计.doc
- (马老师)学期工作总结.doc
- (施工)基础验收资料.doc
- 01生产管理制度.docx
- (用)设计满江红_岳飞.ppt
- 2025年全国演出经纪人员资格认定考试试卷带答案(研优卷).docx
- 2025年全国演出经纪人员资格认定考试试卷完整版.docx
- 2025年全国演出经纪人员资格认定考试试题库及完整答案.docx
- 2025年全国演出经纪人员资格认定考试试卷完美版.docx
- 2025年全国演出经纪人员资格认定考试试卷含答案(实用).docx
- 2025年全国演出经纪人员资格认定考试试卷及答案(各地真题).docx
- 2025年下半年内江市部分事业单位公开考试招聘工作人员(240人)备考题库附答案.docx
- 2025年全国演出经纪人员资格认定考试试卷及答案1套.docx
- 2025年下半年四川成都市郫都区面向社会引进公共类事业单位人员2人备考题库最新.docx
- 2025年下半年内江市部分事业单位公开考试招聘工作人员(240人)备考题库附答案.docx
原创力文档

文档评论(0)