sábado, 1 de agosto de 2009

MATRICES

Rellenar un matriz de cualquier tamaño de ceros. Llenar las diagonales con unos.
Por ejemplo la siguiente matriz de 4 x4:

1001
0110
0110
1001
#include "conio.h"
#include "stdio.h"
#include "math.h"
main(void)
{
int a,b,c,d,e;
int matriz[100][100];
printf("\n\tDIGITE NUMERO DE FILAS ");
scanf("%d",&a);
printf("\n\tDIGITE NUMERO DE COLUMNAS ");
scanf("%d",&b);
for(c=0;a>c;c++)
{
for(d=0;b>d;d++)
{
if(c==d)
matriz[c][d]=1;
if(c+d==a-1)
matriz[c][d]=1;
}
}
for(c=0;a>c;c++)
{
for(d=0;b>d;d++)
{
printf("\n\t%d",matriz[c][d]);
}
}
getch();
}

No hay comentarios:

Publicar un comentario