Jump to content

Alguém pode me ajudar nesse exercício por favor?


William Minerva

Recommended Posts

Eu escrevi o seguinte programa:

#include <stdio.h>
#include <stlib.h>

int main()
{
    int i, j, det;
    
    int matriz[3][3];
    
    for(i=0; i<3; i++)  {
        for(j=0; j<3; j++)  {
            scanf("%d", &matriz[i][j]);
        }
    }
    
    det = (matriz[0][0]*matriz[1][1]*matriz[2][2]) + (matriz[0][1]*matriz[1][2]*matriz[2][0]) + (matriz[0][2]*matriz[1][0]*matriz[2][1]) 
    - ((matriz[0][1]*matriz[1][0]*matriz[2][2]) + (matriz[0][0]*matriz[1][2]*matriz[2][1]) + (matriz[0][2]*matriz[1][1]*matriz[2][0]));
    
    printf("%d", det);
    
    return 0;
}

 

Mas como eu posso ler as matrizes utilizando os comandos while e do-while?

Link to comment
Share on other sites

Olá @William Minerva

É Isso mesmo, as diferenças são poucos e orbitam a sintaxe porque é logicamente igual. Para fim de exemplo, suponho fazer o somatório dos itens de uma lista de n-inteiros. Para isso usarei: for {} e do {} while.

 

Exemplo

— escrevo um programa que informada a lista de n-termos responde com somatório dos termos.

C language /> _

#include"stdio.h"
int
main (void) {
  #define n	(8)
  int termos[n] = { 1,2,3,4,5,6,7,8 };
  unsigned long i;

  int for_somatorio = 0;
  printf ("FOR-SOMATORIO\n(");
  for (i = 0;  i < n;  ++i) {
      printf (" %d ", termos[i]);
      for_somatorio += termos[i];
  }
  printf (") = %d\n\n", for_somatorio);

  int do_somatorio = 0;
  printf ("DO WHILE-SOMATORIO\n(");
  i = 0;
  do {
      printf (" %d ", termos[i]);
      do_somatorio += termos[i];
  }
  while (++i,  i < n);
  printf (") = %d\n\n", do_somatorio);
  
  printf ("Fim-programa\n");
  return 0;
}

SAÍDA

1704488622_Semttulo.thumb.png.10097d12190fc56fbb22daf7ef1bc394.png

[?— notou..., 'sintaxe' distinta, resultados iguais.

Edited by mauro_b
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...