Guest User

Untitled

a guest
Jun 24th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. main()
  4. {
  5. int mat[4][4];
  6. int l=0, c=0, soma=0, media=0, n=0;
  7.  
  8. for(l=0; l<4; l++)
  9. {
  10. for(c=0; c<4; c++)
  11. {
  12. print1:
  13. printf("digite o numero da linha %i e coluna %i: \n", l, c);
  14. if(l==0 && c==0)
  15. {
  16. scanf("%i", &mat[l][c]);
  17. if(mat[l][c]<0||mat[l][c]>100||mat[l][c]<=20||mat[l][c]%2!=0)
  18. {
  19. printf("Erro");
  20. goto print1;
  21. }
  22. }
  23. else
  24. {
  25. scanf("%i",&mat[l][c]);
  26. if(mat[l][c]!=mat[l][c-1]-2||mat[l][c]>100||mat[l][c]<0||mat[l][c]%2!=0)
  27. {
  28. printf("Erro");
  29. goto print1;
  30. }
  31. }
  32. }
  33.  
  34. }
  35.  
  36. for(l=0;l<4;l++)
  37. {
  38. for(c=0;c<4;c++)
  39. {
  40. if(l==c)
  41. {
  42. soma=soma+mat[l][c];
  43. n++;
  44. }
  45. }
  46. }
  47.  
  48. for(l=0;l<4;l++)
  49. {
  50. for(c=0;c<4;c++)
  51. {
  52. printf("%d ",mat[l][c]);
  53. }
  54. printf("\n");
  55. }
  56.  
  57. media=soma/n;
  58. printf("A media dos valores da diagonal principal e: %d", media);
  59.  
  60. }
Add Comment
Please, Sign In to add comment