急。。。求3道C++题答案,在线等。

来源:百度知道 编辑:UC知道 时间:2024/06/26 00:49:39
1. 利用函数模板程序编写求两个数据中的最小值。
2. 编写程序,输出 “Hello,world!”。
3. 编写程序计算求和 1+2…+100 。

1.int min(int a,int b)
{if a>b
return b;
else return a;
}
2.cout<<"Hello world"<<endl;
3.
int sum=0;
for(int i=1;i<=100;i++)
{sum=sum+i;
}
cout<<sum;

1、函数模板
min为C++函数库中的函数,建议需要自己写的换个函数名字

#include <iostream>
using namespace std;

template<class T> T theMin(T a, T b)
{
if(a > b)
return b;
else
return a;
}

int main()
{
int x = 1, y = 2;
double a = 3.2, b = 2.4;

cout << theMin(x, y) << endl;
cout << theMin(a, b) << endl;

return 0;
}

2、
#include <iostream>
using namespace std;

int main()
{
cout<<"Hello world"<<endl;

return 0;
}

3、

#include <iostream>
using namespace std;

int main()
{