练习1.2
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
system("pause");
return -1;
}
练习1.3
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
练习1.4
#include <iostream>
using namespace std;
int main()
{
int num1,num2;
cout<<"please iput two numbers:"<<endl;
cin>>num1>>num2;
int product=num1*num2;
cout<<"The result is:"<<endl;
cout << product << endl;
return 0;
}
练习1.9
#include <iostream>
using namespace std;
int main()
{
int tempNum=50;
int sums=0;
while(tempNum<=100)
{
sums=sums+tempNum;
tempNum=tempNum+1;
}
cout << "The sum between 50 to 100 is " << sums << endl;
return 0;
}
练习1.10
#include <iostream>
using namespace std;
int main()
{
int num=10;
while(num>=0){
cout<<num--<<' ';
}
cout<<endl;
return 0;
}
练习1.11
#include <iostream>
using namespace std;
int main()
{
cout << "please enter two numbers:" << endl;
int num1,num2;
cin>>num1>>num2;
if(num1>=num2)
{
while(num2<=num1)
{
cout<<num2++<<' ';
}
cout<<endl;
}
else
{
while(num1<=num2)
{
cout<<num1++<<' ';
}
cout<<endl;
}
return 0;
}
1.14:
for循环初始化和修改都在语句头,形式较为简洁,且适用于循环次数已知的情况,而while循环适合于循环次数不一定的情况
1.