C++第一章的题目
来源:互联网 发布:淘宝一阳指在哪里 编辑:程序博客网 时间:2024/05/22 18:45
第一章
T7
#include<iostream>
using namespace std;
int main()
{
int max (int x =10, int y =20);
max();
cout << " max = " << max() << endl;
return 0;
}
int max ( int x, int y)
{
if (x>y) return x;
else return y;
}
T8
#include<iostream>
using namespace std;
int max( int &a, int &b)
{
if(a > b)
cout << a << " "<< b << endl;
else
cout << b << " "<< a << endl;
return 0;
}
int main()
{
int i , j;
cin >> i >> j;
max( i , j );
return 0;
}
T9
#include<iostream>
using namespace std;
int paixu( int &a, int &b, int &c)
{
if( a < b)
{
if( b < c)
{
cout << "a < b < c" << endl;
}
else if ( a < c )
{
cout << "a < c < b" << endl;
}
else
{
cout << "c < a < b" << endl;
}
}
else if ( b > c )
{
cout << " c < b < a " << endl;
}
else if ( a > c)
{
cout << " b < a < c " << endl;
}
else
{
cout << " b < c < a " << endl;
}
return 0;
}
int main()
{
int i , j ,k;
cout << "a = ";
cin >> i;
cout << "b = ";
cin >> j;
cout << "c =" ;
cin >> k;
paixu (i, j, k);
return 0;
}
T10
#include<iostream>
#include<string>
using namespace std;
int main()
{
string a = "abc";
string b = "cba";
a = a + b;
cout << " a = " << a << endl;
return 0;
}
T11
#include<iostream>
#include<string>
using namespace std;
int main()
{
string word;
cout << "请输入字符串: " ;
cin >> word;
int i;
cout <<"倒序的字符串是: ";
for ( i = word.length(); i > 0 || i== 0; i--)
cout << word[i];
cout << endl;
return 0;
}
T12
#include<iostream>
#include<string>
using namespace std;
void jixupaixu(string a[])
{
int i, j ;
string temp;
for(i = 0; i < 4; i++) // 为什么这里是排3下。5个字符串啊。 排四下就错。。
{
for(j = 0; j < 4-i; j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}
int main()
{
string a[5];
int i;
for(i = 0; i < 5; i++)
{
cin >> a[i];
}
jixupaixu(a);
for(i = 0; i < 5; i++)
{
cout << a[i] << " ";
}
return 0 ;
}
T13
#include<iostream>
using namespace std;
int paixu( int *a )
{
int i , j , t;
for(i = 0; i < 10; i++ )
{
for( j = 0; j < 10 - i; j++ )
{
if( a[j] > a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
return 0;
}
float paixu( float *a )
{
int i , j , t;
for(i = 0; i < 10; i++ )
{
for( j = 0; j < 10 - i; j++ )
{
if( a[j] > a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
return 0;
}
double paixu( double *a )
{
int i , j , t;
for(i = 0; i < 10; i++ )
{
for( j = 0; j < 10 - i; j++ )
{
if( a[j] > a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
return 0;
}
int main()
{
int a[10] = {1, 5 ,9 ,99, 777, 234, 213, 321,5452,42};
float b[10] = { 1.1, 22.1, 9.9, 55.1, 66.02, 66.1, 22.2, 44.9, 489.14564, 1.2365};
double c[10] = {1,2,3,4,5,6,7,9,8,40};
int i;
paixu(a);
{
for (i = 0; i<10; i++)
{
cout << a[i] << " " ;
}
cout << endl;
}
paixu(b);
{
for (i = 0; i<10; i++)
{
cout << b[i] <<" ";
}
cout << endl;
}
paixu(c);
{
for (i = 0; i<10; i++)
{
cout << c[i] <<" ";
}
cout << endl;
}
return 0;
}
T14
#include<iostream>
using namespace std;
template <typename T>
T paixu(T*a)
{
int i, j, t;
for(i = 0 ; i < 5 ; i++)
{
for (j = 0 ; j < 5-i; j++ )
{
if( a[j] > a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
return 0;
}
int main()
{
int a[5] = {1,55,2,3,4};
float b[5] = {1.1, 2.2,3.3,4.4,5.5};
double c[5] = {1.11,2.22,3.33,4.44,5.11};
int i = 0;
paixu(a);
{
for(i = 0 ; i < 5; i++)
{
cout << a[i] << " ";
}
cout << endl;
}
paixu(b);
{
for(i = 0 ; i < 5; i++)
{
cout << b[i] << " ";
}
cout << endl;
}
paixu(c);
{
for(i = 0 ; i < 5; i++)
{
cout << c[i] << " ";
}
cout << endl;
}
return 0;
}
- C++第一章的题目
- 第一章的C语言课
- C语言程序设计的题目
- 第一章 题目和答案
- 第一章第二章各个题目的运行结果图
- C语言 第一章 程序设计的基本概念
- 第一章:C穿越时空的迷雾
- C++primer 第一章网站上的代码
- C解决的小小题目
- 关于C语言的题目
- 一道C语言的题目
- 一点 C 的小题目
- 做错的题目c/c++
- 简单的c语言题目
- 有趣的C语言题目
- c 的一个简单题目
- 二、考研题目 第一章 绪论
- 考研题目 第一章 绪论 答案
- NAVICAT注册码
- GB-T 28168-2011 信息技术 中间件 消息中间件技术规范
- Flex 3 mx:List 上下移动demo
- 动态树LCT||树链剖分+线段树(SPOJ QTREE3 - Query on a tree again!)
- 今天买了一瓶波尔多的92年红星二锅头
- C++第一章的题目
- AMD、CMD、UMD 模块的写法
- 韩红拿歌王被冷落:夺冠只是幸运而已
- 记录一个SHADOWSOCKS帐号。。
- 对话孙楠:我问心无愧 芒果台要感谢我
- 二叉树
- MySQL 更改表外键报错:ERROR 1025: Error on rename of .... (errno: 150)
- Android圆型头像实现-可设置边框
- 诸葛紫岐正接洽张柏芝 条款还在商讨中