您的位置:首页 > 编程语言 > C语言/C++

第一个c++程序

2014-03-14 21:08 162 查看
[html] view
plaincopy

/*********************************

*** 功能:输出姓名、班级、学号****

*********************************/

#include <iostream> //编译预处理命令

using namespace std; //使用标准名空间 std

int main() //主函数

{

cout<<"姓名:蔡金辉\n";

cout<<"班级:自动化1121\n";

cout<<"学号:201211632101\n";

return 0;

}

[html] view
plaincopy

/*******************************************

** 功能:求两个数的最大值 **

********************************************/

#include<iostream> //编译预处理命令

using namespace std; //使用标准名空间 std

int max(int x,int y) //求两个数的最大值函数

{

int t; //定义一个整形变量 t

if (x>y) //if判断语句,判断x>y是否成立

t = x; //最终将最大值赋予给t

else

t = y;

return t; //return返回一个整型值t给主函数

}

/* 以下是主函数 */

int main() //主函数

{

int number1,number2; //定义两个基本整型变量 number1和number2

cout<<"请输入两个数:"; //输出“请输入两个数:”

cin>>number1>>number2; //从键盘上输入两个变量的值

int maxValue; //定义一个整形变量 maxValue(最大值)

maxValue = max(number1,number2); //调用求最大值的函数 max

//并赋值给变量 maxValue

cout<<"最大值 = "<<maxValue<<endl; //输出最大值

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: