|
|
back to boardhere is the mathematic method Posted by esger 30 Apr 2008 15:21 #include<iostream.h> int i,j; long a[101][101],n; int main(){ cin>>n; for(i=1;i<n+1;i++) { a[i][n]=i*(i+1)/2; } for(i=1;i<n;i++) { for(j=n-1;j>=i;j--) { a[i][j]=a[i][j+1]+n-j+i-1; } } for(i=2;i<n+1;i++) { for(j=i-1;j>0;j--) { a[i][j]=a[i][j+1]+n+j-i; } } for(i=1;i<n+1;i++) { for(j=1;j<n+1;j++) cout<<a[i][j]<<" "; cout<<"\n"; } return 0; } Re: here is the mathematic method This method is easy but very interesting! Re: here is the mathematic method Posted by null 10 Oct 2011 08:33 Nice, but there's no need in arrays if you're trying to use some math. My solution uses just seven integers and that's enough. |
|
|