domingo, 9 de março de 2014

Apagando e separando as Diagonais de uma Matriz

Mais um programa com Matriz, e desta vez,
mostro como apagar e separar as diagonais.


Veja o código do programa abaixo:

#include <stdio.h>
#include <conio.h>
#define tam 10
void Janela5(){
    int lin, col;
    col = 0;
    for ( lin = 0; lin <= 25; lin++ ){
        for ( col = 0; col <= 80; col++ ){
            gotoxy( col, lin );
            if ( lin == 2 ){textbackground(LIGHTBLUE);printf( " ");}
            if ( col == 1 ){textbackground(LIGHTBLUE);printf(" ");}
            if ( lin == 25 ){textbackground(LIGHTBLUE);}
            if ( col == 80 ){textbackground(LIGHTBLUE);printf(" ");}
        }
    }textbackground( BLACK);
}
int main(){
    int Vet [ tam ] [ tam ] ;
    system ("title APAGANDO E SEPARANDO AS DIAGONAIS DE UMA MATRIZ");
    Janela5();
    textcolor(LIGHTRED);gotoxy(20,7);printf("APAGANDO E SEPARANDO AS DIAGONAIS DE UMA MATRIZ");
    textcolor(YELLOW);gotoxy(25,10);printf("Programa desenvolvido por:");
    textcolor(LIGHTCYAN);gotoxy(52,10);printf("Samuel Lima");
    textcolor(LIGHTGREEN);gotoxy(34,12);printf("sa_sp10@hotmail.com");
    textcolor(LIGHTRED);gotoxy(31,15);printf("PRESSIONE QUALQUER TECLA");
    getche();system("cls");Janela5();
    textcolor(LIGHTRED);gotoxy(20,4);printf("APAGANDO E SEPARANDO AS DIAGONAIS DE UMA MATRIZ");
    int i = 0, j = 0, t = 0;
    for( i = 0; i < tam; i++ ){
        gotoxy(18, i + 8);
        for( j = 0; j < tam; j++ ){
            t++;
            Vet [ i ] [ j ]  = t;
            textcolor(YELLOW);
            if ( i == j || j == ( 1 + 8 - i ) ){
                textcolor(BLACK);
            }
            printf(" %3d ",  Vet [ i ] [ j ] );
        }
    }
    textcolor(LIGHTRED);gotoxy(31,21);printf("PRESSIONE QUALQUER TECLA");
    getche();
    for ( i = 0; i < tam; i++ ){
        gotoxy(18, i + 8);
        textcolor(YELLOW);
        for ( j = 0; j < tam; j++ ){
            if ( j  == ( 1 + 9 - i ) ){
                textcolor(WHITE);
                printf("     " );
            }
            printf(" %3d ", Vet [ i ] [ j ] );
        }
    }
    textcolor(LIGHTRED);gotoxy(31,21);printf("PRESSIONE QUALQUER TECLA");
    getche();
    for ( i = 0; i < tam; i++ ){
        gotoxy(18, i + 8);
        textcolor(YELLOW);
        for ( j = 0; j < tam; j++ ){
            if ( j == i ) {
                textcolor(WHITE);
                printf("     " );
            }
            printf(" %3d ", Vet [ i ] [ j ] );
        }
    }
    gotoxy(30,21);printf("       ");
    textcolor(LIGHTRED);gotoxy(37,21);printf("MUITO OBRIGADO !!!");
    getche();
}

Nenhum comentário:

Postar um comentário

Observação: somente um membro deste blog pode postar um comentário.