#include<iostream>
using namespace std;
//申请一个数组,其中元素有100个并一次赋值为1~100;
//每行输出10个数
int main()
{
int *p = new int[100];
if (p == NULL) {
cout << "application error" << endl;
return 0;
}
for (int i = 1; i <= 100; i++) {
p[i] = i;
cout << " " << p[i] ;
if (i % 10 == 0)
cout<< endl;
}
delete [] p;
return 0;
}
方法2
#include<iostream>
using namespace std;
//申请一个数组,其中元素有100个并一次赋值为1~100;
//每行输出10个数
int main()
{
int *p = new int[100];
if (p == NULL) {
cout << "application is error" << endl;
} else {
for (int i = 0; i < 100; i++){
p[i] = i +1;
cout << " " << p[i] ;
if( i % 10 == 0) {
cout << endl;
}
}
}
delete [] p;
return 0;
}
总结:方法2比较简洁