Acasa Tehnologie >Matrice parcurgere sarpe (snake)

>Matrice parcurgere sarpe (snake)

by Dragos Schiopu

>

//parcurgere matrice Snake
#include <stdio.h>
#include <conio.h>
#include <math.h>


void citire(int m, int n, int a[20][20],char c)
{
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
{
printf("%c[%i][%i]=",c,i,j);
scanf("%d",&a[i][j]);
}
}


void afisare(int m, int n, int a[20][20])
{
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
printf(" %d ",a[i][j]);
printf("n");
}
}

main()
{
int n;
int a[20][20];

printf("n=");
scanf("%d",&n);

printf("nCitire matricen");
citire(n,n,a,'A');
printf("Afisare matrice n");
afisare(n,n,a);

printf("nParcurgere Snaken");
for(int i=1;i<=n;i++)
{
if(i%2!=0)
{

for(int j=1;j<=n;j++)
printf(" % d ",a[i][j]);
}
else
{
for(int j=n;j>=1;j--)
printf(" % d ",a[i][j]);
}
}

return 0;
}

s-ar putea sa-ti placa