Advertisement
AprendizDeC1224

Diagonal principal y secundaria

Jun 27th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int imprimir_arreglo (int **arreglo,int matriz)
  4. {
  5. int i, j, suma,producto;
  6. printf("\n");
  7. suma=0;
  8. producto=1;
  9. for(i=0;i<matriz;i++)
  10. {
  11. for(j=0;j<matriz;j++)
  12. {
  13. printf("Introduzca el numero al elemento[%d][%d]: ",i+1,j+1);
  14. scanf("%d",&arreglo[i][j]);
  15. if(i==j)
  16. {
  17. suma+=arreglo[i][j];
  18. }
  19. }
  20. }
  21. for(i=0;i<matriz;i++)
  22. {
  23. for(j=0;j<matriz;j++)
  24. {
  25. if(i+j==matriz-1)
  26. {
  27. producto*=arreglo[i][j];
  28. }
  29. }
  30. }
  31. printf("\n");
  32. for(i=0;i<matriz;i++)
  33. {
  34. for(j=0;j<matriz;j++)
  35. {
  36. printf("\t%d ",arreglo[i][j]);
  37. }
  38. printf("\n");
  39. }
  40. printf("\n");
  41. printf("La suma de la diagonal principal es: %d \n",suma);
  42. printf("El producto de la diagonal secundaria es: %d \n",producto);
  43. }
  44.  
  45. void main()
  46. {
  47. int matriz;
  48.  
  49. printf("Dame las dimensiones de la matriz cuadrada: ");
  50. scanf("%d",&matriz);
  51.  
  52. int arreglo[matriz][matriz];
  53.  
  54. imprimir_arreglo(arreglo,matriz);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement