Guest User

Untitled

a guest
Nov 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. void print_blank(int n)
  5. {
  6. for(int i =0; i < n; i++){
  7. printf(" ");
  8. }
  9. }
  10.  
  11. int max(int h, int w, int nb, int arr[h][w])
  12. {
  13. int ans = arr[0][nb];
  14. for(int i =0; i < h; i++){
  15. if(ans <= arr[i][nb]){
  16. ans = arr[i][nb];
  17. }
  18. }
  19. return ans;
  20. }
  21.  
  22. int len (int n)
  23. {
  24. return ceil(log10(n));
  25. }
  26.  
  27. void pretty_print(int h, int w, int mtx[h][w])
  28. {
  29. int tmp = 0;
  30. int m[w];
  31.  
  32. for(int l=0;l<w;l++){
  33. m[l] = len(max(h,w,l,mtx));
  34. }
  35.  
  36. for(int i =0; i < h; i++){
  37. printf("%d : ", m[i]);
  38. for(int j =0; j < w; j++){
  39. tmp = len(mtx[i][j]);
  40. if(!tmp)
  41. tmp++;
  42. print_blank(m[j]-tmp);
  43. printf("%i ", mtx [i][j]);
  44. }
  45. printf("\n");
  46. }
  47. }
  48.  
  49. int main ()
  50. {
  51. int h =0;
  52. int w =0;
  53. printf("Dame el número de filas: ");
  54. scanf("%i", &h);
  55. printf("Dame el número de las columnas: ");
  56. scanf ("%i", &w);
  57. int mtx [h][w];
  58. for(int i =0; i < h; i++){
  59. for(int j =0; j < w; j++){
  60. printf("Dame el número [%i][%i]: ", i, j);
  61. scanf("%i", &mtx [i][j]);
  62. }
  63. }
  64. pretty_print(h, w, mtx);
  65. return 0;
  66. }
Add Comment
Please, Sign In to add comment