#include <iostream>
#include <vector>
using std::cout;
using std::endl;
using std::cin;
using std::vector;
bool test(int num,int&last)
{
int tmp = num*2;
int i=1;
while(i*(i+1)<tmp)
{
i++;
}
if(i*(i+1)==tmp)
{
last = i;
return true;
}
else
{
return false;
}
}
int main()
{
int a;
vector<int> ivec;
while(cin>>a&&!(a==0))
{
ivec.push_back(a);
}
for(vector<int>::size_type ix =0; ix <ivec.size(); ++ix)
{
int last = 0;
if(test(ivec[ix],last))
{
cout<<ivec[ix]<<" is a triangular number."<<endl;
for(int i=1;i<=last;i++)
{
for(int j=1;j<=i;j++)
{
cout<<"*";
}
cout<<endl;
}
}
else
{
cout<<ivec[ix]<<" is not a triangular number."<<endl;
}
}
return 0;
}
1007
最新推荐文章于 2021-04-06 04:15:49 发布