第一个c++程序

[html]  view plain copy
  1. /*********************************   
  2. *** 功能:输出姓名、班级、学号****   
  3. *********************************/    
  4.     
  5. #include <iostream>                       //编译预处理命令  
  6. using namespace std;                      //使用标准名空间 std  
  7.   
  8. int main()                                 //主函数  
  9. {    
  10.     cout<<"姓名:蔡金辉\n";                 
  11.     cout<<"班级:自动化1121\n";                  
  12.     cout<<"学号:201211632101\n";    
  13.     return 0;    
  14.     
  15. }    

[html]  view plain copy
  1. /*******************************************    
  2. **          功能:求两个数的最大值        **    
  3. ********************************************/      
  4. #include<iostream>                       //编译预处理命令      
  5. using namespace std;                    //使用标准名空间 std      
  6.       
  7.       
  8. int max(int x,int y)                    //求两个数的最大值函数      
  9. {      
  10.     int t;                          //定义一个整形变量 t      
  11.     if (x>y)                        //if判断语句,判断x>y是否成立      
  12.         t = x;                      //最终将最大值赋予给t    
  13.     else                                 
  14.             t = y;                        
  15.     return t;                       //return返回一个整型值t给主函数      
  16. }      
  17.       
  18. /* 以下是主函数 */      
  19. int main()                                  //主函数      
  20. {      
  21.     int number1,number2;                //定义两个基本整型变量 number1和number2      
  22.     cout<<"请输入两个数:";             //输出“请输入两个数:”      
  23.     cin>>number1>>number2;              //从键盘上输入两个变量的值      
  24.     int maxValue;                       //定义一个整形变量 maxValue(最大值)      
  25.     maxValue = max(number1,number2);    //调用求最大值的函数 max      
  26.                                         //并赋值给变量 maxValue      
  27.     cout<<"最大值 = "<<maxValue<<endl;  //输出最大值      
  28.       
  29.       
  30.     return 0;      
  31. }    
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值