首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

求一段程序解决方案

2013-09-09 
求一段程序实现如下功能:一个数组a[10],第一次a[0]置一,然后a[1]置一,a[0]置2.....依次类推。用循环语句编

求一段程序
实现如下功能:
一个数组a[10],第一次a[0]置一,然后a[1]置一,a[0]置2.....依次类推。
用循环语句编写吧

求一段程序解决方案

附上自己写的,不理想,求大神帮忙
#include "iostream"
using namespace std;

int main()
{
const int n=10;
int a[n]={0};
for (int i=0;i<n;i++)
{
for (int j=0;j<i;j++)
{
a[i]=a[i]+1;
cout<<"a["<<i-j<<"]="<<a[i]<<"  ";
    }
cout<<endl;
}


} c 循环 连续加一
[解决办法]


#include "iostream"
using namespace std;

int main()
{
const int n=10;
int a[n]={0};
int i;
int j;
for (i=1;i<n;i++)
{
for (j=i;j>0;j--)
{
a[j]=j;
cout<<"a["<<j<<"]="<<a[j]<<"  ";
}
cout<<endl;
}
return 0;
}

热点排行