[C++]学习C++的第一次作业

C++ How to Program :  2.19

2015.03.11

现在看起来很臃肿,没有注释没有作者时间目的。即使有VB的一点点基础,也还是非常痛苦地才能完成此次任务。


2.19,输入三个数,输出他们的和,平均值,积,最大最小值。

#include <iostream>

using std::cout;
using std::cin;
using std::endl; //claim name space and operaters.

int main()
{
	int num1;
	int num2;
	int num3;
	int sum;
	int avr;
	int product;//claim variables as integer.
	
	cout << "Input three different integers: ";
	cin >> num1 >> num2 >> num3; // use cin and cout to input and output

	sum = num1 + num2 + num3;//calculate sum.
	cout << "Sum is " << sum << endl;

	avr = sum / 3;
	cout << "Average is " << avr << endl;

	product = num1 * num2 * num3;
	cout << "Product is " << product << endl;

	if ( num1 < num2 && num1 < num3 )
    cout << "Smallest is " << num1 << endl;
    else if ( num2 < num3 )
    cout << "Smallest is " << num2 << endl;
    else
    cout << "Smallest is " << num3 << endl;
	//not the easiest way to find out the edge.

    if ( num1 > num2 && num1 > num3 )
    cout << "Largest is " << num1 << endl;
    else if ( num2 > num3 )
    cout << "Largest is " << num2 << endl;
    else
    cout << "Largest is " << num3 << endl; 

	system("pause");//used to hold the window. 
	return 0;//needed sometimes when the function needs a feedback.
		
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值