#include<iostream>#include<stdlib.h>#include<string>usingnamespace std;intmain(){
int n, m;int t =0;
cout <<"分别输入两个整数:"<< endl;
cin >> n >> m;
cout << n <<"和"<< m <<"之间所有整数的和为:";/*for (; n <= m; n++)
{
t += n;
}*/
t =(n + m)*(m - n +1)/2;
cout << t << endl;system("pause");return0;}
2
// formore.cpp -- more looping with for#include<iostream>#include<array>constint ArSize =101;// example of external declarationintmain(){
std::array<longdouble, ArSize> factorials;//long double factorials[ArSize];
factorials[1]= factorials[0]=1LL;// 1 L L//for (int i = 2; i <= ArSize; i++)//写成小于等于的话,数组索引会超出数组范围for(int i =2; i < ArSize; i++)
factorials[i]= i * factorials[i -1];for(int i =0; i < ArSize; i++)
std::cout << i <<"! = "<< factorials[i]<< std::endl;// std::cin.get();return0;}
3
#include<iostream>#include<stdlib.h>#include<string>usingnamespace std;intmain(){
int n;int t =0;
cout <<"输入数字(输入0结束):"<< endl;
cin >> n;while(n !=0){
t += n;
cout <<"到目前为止,所有输入的累计和为:"<< t << endl;
cout &l