Neste exemplo, o programa imprime
as diagonais da matriz numa cor em destaque.
#include <stdio.h>
#include <conio.h>
#define tam 10
/*============================================================================*/
void Informe ( ) {
textcolor ( LIGHTBLUE );
gotoxy ( 26, 20 );
printf ( "Criado por: " );
textcolor ( LIGHTMAGENTA );
gotoxy ( 126, 20 );
printf ( "Samuel Lima" );
textcolor ( BLACK );
gotoxy ( 23, 23 );
printf ( " " );
gotoxy ( 26, 21 );
printf ( "sa_sp10@hotmail.com" );
textcolor ( LIGHTRED );
gotoxy ( 36 , 23 );
printf ( "MUITO OBRIGADO" );
}
/*============================================================================*/
void Janela5 ( ){
int lin, col;
col = 0;
system("Color 10");
for ( lin = 2; lin <= 24; lin++ )
for ( col = 3; col <= 78; col++ ) {
gotoxy ( col,lin );
textbackground(WHITE);
printf(" ");
}
}
/*============================================================================*/
int main ( ) {
Janela5 ( );
SetConsoleTitle ("IMPRIMINDO AS DIAGONAIS DE UMA MATRIZ" );
int Vet [ tam ] [ tam ];
textcolor ( LIGHTRED );
gotoxy ( 24, 4 );
printf ( "IMPRIMINDO 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 ( LIGHTRED );
if ( i == j || j == ( 1 + 8 - i ) ) {
textcolor ( BLACK );
}
printf ( " %3d ", Vet [ i ] [ j ] );
}
}
Informe ( );
getche ( );
}
/*============================================================================*/