sexta-feira, 30 de novembro de 2012

Calculando o quadrado de uma Matriz

Calculando o quadrado de uma Matriz, Há alguma novidade nisto?
acredito que não; e quem já está acostumado a mecher com Matrizes em C
verá que o código é simples,veja que foi declarado Cinco Matrizes,todas
de três por três:  sendo
que a Matriz e [  max ] [ max  ]; mostrará os resultados calculados  na operação das duas primeiras
Matrizes: Matriz A ao quadrado,  vêzes Matriz B ao quadrado.

Veja algumas imagens abaixo:







copie, cole e compile o código abaixo:

#include <conio.h>
#include <stdio.h>
#include<math.h>
#define max 3
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(){
system ("title CÁLCULO DO QUADRADO DE UMA MATRIZ");
int i, j , n, m;
int a [ max ] [ max ], b [ max ] [ max ], c [ max ] [ max ], d [ max ] [ max ], e [ max ] [ max ];
Janela5();
textcolor(LIGHTRED);gotoxy(24,3);printf("CÁLCULO DO QUADRADO DE UMA MATRIZ");
textcolor(LIGHTBLUE);gotoxy(29,5);printf("sa_sp10@hotmail.com");
textcolor(LIGHTGREEN);gotoxy(29,7);printf("DADOS PARA A MATRIZ A\n");
textcolor(LIGHTBLUE);gotoxy(20,9);printf("Digite o Número de linhas para Matriz A: ");
textcolor(YELLOW);scanf("%d",&n);fflush(stdin);
textcolor(LIGHTBLUE);gotoxy(20,10);printf("Digite o Número de colunas para Matriz A: ");
textcolor(YELLOW);scanf("%d",&m);fflush(stdin);
textcolor(LIGHTRED);gotoxy(28,17);printf("PRESSIONE QUALQUER TECLA");
getche();system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(24,3);printf("CÁLCULO DO QUADRADO DE UMA MATRIZ");
textcolor(LIGHTBLUE);gotoxy(20,5);printf("Preenchendo as Posições da Matriz A: \n\n");
textcolor(WHITE);
printf("\t\t\t");
for( i = 0; i < n; i++ ){
for( j = 0; j < m; j++ ){
printf("a [ %d ] [ %d ] = ", i, j );
scanf("%d",&a [ i ] [ j ] );
printf("\t\t\t");
}
}
system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(24,3);printf("CÁLCULO DO QUADRADO DE UMA MATRIZ");
textcolor(LIGHTBLUE);gotoxy(29,5);printf("sa_sp10@hotmail.com");
textcolor(LIGHTGREEN);gotoxy(29,7);printf("DADOS PARA A MATRIZ B\n");
textcolor(LIGHTBLUE);gotoxy(20,9);printf("Digite o Número de linhas para Matriz B: ");
textcolor(YELLOW);scanf("%d",&n);fflush(stdin);
textcolor(LIGHTBLUE);gotoxy(20,10);printf("Digite o Número de colunas para Matriz B: ");
textcolor(YELLOW);scanf("%d",&m);fflush(stdin);
textcolor(LIGHTRED);gotoxy(28,17);printf("PRESSIONE QUALQUER TECLA");
getche();system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(24,3);printf("CÁLCULO DO QUADRADO DE UMA MATRIZ");
textcolor(LIGHTBLUE);gotoxy(20,5);printf("Preenchendo as Posições da Matriz B\n\n");
textcolor(WHITE);
printf("\t\t\t");
for( i = 0; i < n; i++ ){
for( j = 0; j < m; j++ ){
printf("b [ %d ] [ %d ] = ", i, j );
scanf("%d",&b [ i ] [ j ] );
printf("\t\t\t");
}
}
system("cls");Janela5();
textcolor(LIGHTRED);gotoxy(24,3);printf("CÁLCULO DO QUADRADO DE UMA MATRIZ");
textcolor(LIGHTBLUE);gotoxy(24,5);printf("Veja abaixo a Matriz A: ");
textcolor(YELLOW);
for( i = 0; i < n; i++ ){
gotoxy(28, i + 7);
for( j = 0; j < m; j++ ){
printf("%4d ",a [ i ] [ j ] );
}
}
textcolor(LIGHTBLUE);gotoxy(24,11);printf("Veja abaixo a Matriz B: ");
textcolor(YELLOW);
for( i = 0; i < n; i++ ){
gotoxy(28, i + 13);
for( j = 0; j < m; j++ ){
printf("%4d ",b [ i ] [ j ] );
}
}
for( i = 0; i < n; i++ ){
for( j = 0; j < m; j++ ){
c [ i ] [ j ] = a [ i ] [ j ] * a [ i ] [ j ];
d [ i ] [ j ] = b [ i ] [ j ] * b [ i ] [ j ];
e [ i ] [ j ] = c [ i ] [ j ] * d [ i ] [ j ];
}
}
textcolor(LIGHTBLUE);gotoxy(18,18);
printf("Abaixo os resultados das duas Matrizes ao Quadrado");
textcolor(YELLOW);
for( i = 0; i < n; i++ ){
gotoxy(28, i + 20);
for( j = 0; j < m; j++ ){
printf("%4d ",e [ i ] [ j ] );
}
}
Sleep(1800);
textcolor(LIGHTRED);gotoxy(35,24);cprintf("O ROCCO AGRADECE!");
getche();
}



Nenhum comentário:

Postar um comentário

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