Cálculo de Determinantes

Publicado por Cleiton Ap. de Souza (última atualização em 10/09/2009)

[ Hits: 12.613 ]

Download determ 3x3-1.cpp




Programa que faz o cálculo de determinantes 2x2 e 3x3.

  



Esconder código-fonte

#include <conio.h>
#include <stdio.h>
//Autor:Denis José Alves, estudante 1° ano de Ciência da Computação da Universidade Anhanguera-UNIFIAN-leme-SP

    int l,c,r,t,q;  
    float v[3][3],p,m,nt;
    void a(){
    printf("\nSe voce quizer resolver matriz 2x2 tecle 1, para 3x3 tecle 0");
    scanf("%d",&r);    
    if(r==0){
    printf("\n[0,0] [0,1] [0,2]\n[1,0] [1,1] [1,2]\n[2,0] [2,1] [2,2]");
    for(l=0;l<3;l++){
                     for(c=0;c<3;c++){                                                       
                                      printf("\nDigite os numeros da matriz:");
                                      scanf("%f",&v[l][c]);
                                      }}
                                      for(l=0;l<3;l++){
                                                       for(c=0;c<3;c++){
                                                                        p=(+((v[0][0]*v[1][1]*v[2][2])+(v[0][1]*v[1][2]*v[2][0])+(v[0][2]*v[1][0]*v[2][1])));
                                                                        m=(-((v[0][2]*v[1][1]*v[2][0])+(v[0][0]*v[1][2]*v[2][1])+(v[0][1]*v[1][0]*v[2][2])));
                                                                        nt=p+m;}}                                                                        
                                                                        printf("\nResultado da matriz 3x3 =  ");
                                                                        printf("(%.2f) + (%.2f) = %.f",p,m,nt);  
                                                                        printf("\n\n");                                                       
                                                                        for(l=0;l<3;l++)
                                                                           {
                                                                             for(c=0;c<3;c++){
                                                                             if (c==0) 
                                                                             {printf("[ ");}
                                                                             printf("%.f",v[l][c]);
                                                                             printf(" ");
                                                                              }
                                                                              printf("]\n");
                                                                              }}
                                                                                                          else{
                                                                                                          printf("\n[0,0] [0,1]\n[1,0] [1,1]"); 
                                                                                                          for(l=0;l<2;l++){
                                                                                                                           for(c=0;c<2;c++){
                                                                                                                                            printf("\nDigite os numeros da matriz:");
                                                                                                                                            scanf("%f",&v[l][c]);}}
                                                                                                                                            for(l=0;l<2;l++){
                                                                                                                                                             for(c=0;c<2;c++){
                                                                                                                                                                              p=v[0][0]*v[1][1];
                                                                                                                                                                              m=v[0][1]*v[1][0];
                                                                                                                                                                              nt=(p)-(m);}}
                                                                                                                                                                              printf(" =",p,m);
                                                                                                                                                                              printf("\nResultado da matriz 2x2 = (%.f) - (%.f) = %.f",p,m,nt);
                                                                                                                                                                              printf("\n\n");                                                                                                                                                              
                                                                                                                                                                              for(l=0;l<2;l++){
                                                                                                                                                                                               for(c=0;c<2;c++){
                                                                                                                                                                                                                if (c==0) 
                                                                                                                                                                                                               {printf("[ ");}
                                                                                                                                                                                                               printf("%.f",v[l][c]);
                                                                                                                                                                                                               printf(" ");}
                                                                                                                                                                                                               printf("]\n");} }
                                                                                                                                                                                                               printf("\nVoce deseja continuar sim-2 ou nao-3?");
                                                                                                                                                                                                               scanf("%d",&t);
                                                                                                                                                                                                               q=q+1;}
                                                                                                                                                                                                               
                                                                                                                                                                                                               int main(){
                                                                                                                                                                                                                   do{
                                                                                                                                                                                                                   a();
                                                                                                                                                                                                                   }while(t!=3);
                                                                                                                                                                                                                   printf("Numero total de interacoes = %d",q);
                                                                                                                                                                                                                   getch();
                                                                                                                                                                                                                  
                                                                        
                                                                        return 0; 
                                                                        }
                                                                        
                                                                        
                                      

Scripts recomendados

brincando com caracteres

C --> Calculadora de equações de 2º grau explicada.

SIMPCalc

Conta Bit em C

Árvores Binárias em C


  

Comentários
[1] Comentário enviado por cleitonapsouza em 24/09/2009 - 14:24h

Em Breve dariei uma organizada no código...

[2] Comentário enviado por removido em 13/06/2012 - 03:19h

Eu apertei F5 uma dúzia de vezes aqui e o código está literalmente saindo à direita do monitor.
Vazando a tela.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts