int x=0,y;
while(x<=10)
{ y=x*x;
printf("%d",y);
x++;
}
顶~~~~~~~~~~
我也写了一个,太繁了。呵呵~~~~~~~~
#include <iostream.h>
class Num
{
public:
Num()//默认构造函数
{
cout<<"Destructor factor!"<<endl;
}
void pingfang(int a[],int n);//求平方
void lifang(int a[],int n);//求立方
void Display();
private:
int b[11];
};
void Num::pingfang(int a[],int n)
{
//Num k;
for (int i=0;i<n;i++)
b[i]=a[i]*a[i];
//return k;
}
void Num::lifang(int a[],int n)
{
//double k;
for (int i=0;i<n;i++)
b[i]=a[i]*a[i]*a[i];
//return k;
}
void Num::Display()
{
for (int i=0;i<11;i++)
cout<<b[i]<<" ";
cout<<endl;
}
void main()
{
int a[11],i;
for (i=0;i<11;i++)
a[i]=i;
Num s1;
cout<<"0--10的平方为:"<<endl;
s1.pingfang(a,11);
s1.Display();
cout<<"0--10的立方为:"<<endl;
s1.lifang(a,11);
s1.Display();
}