用C++写的
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main()
{
bool Flag=false;
vector<int> v;
int a[]={1,2,3,4,5,6,7,8,9};
cout<<"请问您要从: ";
for(int i=0;i<9;i++)
cout<<" "<<a[i];
cout<<" 中选择 ";
cout<<"几个数相加。"<<endl;
int b,sum(0),j(1);
cin>>b;
cout<<"请分别输入您要加的数"<<endl;
while(j<=b)
{
int c;
cin>>c;
switch(c)
{
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:Flag=true;break;
default:break;
}
if(Flag)
v.push_back(c);
else
Flag=false;
j++;
}
for(int k=0;k<v.size()-1;k++)
{
sum+=v[k];
cout<<v[k]<<"+";
}
cout<<v[v.size()-1]<<" = "<<sum+v[v.size()-1]<<endl;
return 0;
}