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.
}