2013年11月15日 星期五

聖誕樹*2

#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int x,y,z,a;
for(x=0;x<10;x++)
{
for(y=x;y<10;y++)
cout<<" ";
for(z=2*x+1;z>0;z--)
cout<<"*";
for(y=2*x;y<20;y++)
cout<<" ";
for(z=2*x+1;z>0;z--)
cout<<"*";
cout<<endl;
    }
     for(a=0;a<3;a++)
cout<<"        *****                *****"<<endl;
}

2013年11月8日 星期五

C++之水仙花數



#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c,d,e;
for(a=1;a<9;a++)
{
     for(b=0;b<9;b++)
     {
for(c=0;c<9;c++)
{
d=c*c*c+b*b*b+a*a*a;
e=100*a+10*b+c;
if(d==e)
cout<<e<<endl;
}
     }

}
system("pause") ;
}
水仙花數是每個位數的立方為自身的三位數,例如:153=3*3*3+5*5*5+1*1*1