cum generez o matrice care arata

1 5 9 13

2 6 10 14

3 7 11 15

4 8 12 16

2
patratica (n*n) sau normala (n*m) ?
patratica
intr-un program
pascal
Ok, data viitoare te rog sa dai toate datele necesare in cerinta.Ex: "Program Pascal, matrice patratica care afiseaza...".Astfel ti-as fi scris ca nu stiu Pascal foarte bine si nu te pot ajuta la problema asta :)

Răspunsuri

2014-05-21T16:25:28+03:00
#include <iostream>
#include <iomanip>

using namespace std;
int main()
{int n,i,j,a[30][30];

cout<<"n="; cin>>n;


for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
a[i][j]=j*4+i-4;


  for (i=1;i<=n;i++)
  {for (j=1;j<=n;j++)
  cout<<setw(4)<<a[i][j];
  cout<<endl;
 }

}


1 5 1
2014-05-21T20:54:56+03:00
Int main(){
int a[20][20],i,j,n;
cout<<"n=";cin>>n;

 for(i=1;i<=n;i++){

 a[i][1]=i;
 for(j=2;j<=n;j++){
 a[i][j]=a[i][j-1]+n;
 }
 }
 for(i=1;i<=n;i++){
 for(j=1;j<=n;j++)

 cout<<a[i][j]<<" ";
 cout<<endl;
 }

 return 0;
}