Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- void print_blank(int n)
- {
- for(int i =0; i < n; i++){
- printf(" ");
- }
- }
- int max(int h, int w, int nb, int arr[h][w])
- {
- int ans = arr[0][nb];
- for(int i =0; i < h; i++){
- if(ans <= arr[i][nb]){
- ans = arr[i][nb];
- }
- }
- return ans;
- }
- int len (int n)
- {
- return ceil(log10(n));
- }
- void pretty_print(int h, int w, int mtx[h][w])
- {
- int tmp = 0;
- int m[w];
- for(int l=0;l<w;l++){
- m[l] = len(max(h,w,l,mtx));
- }
- for(int i =0; i < h; i++){
- printf("%d : ", m[i]);
- for(int j =0; j < w; j++){
- tmp = len(mtx[i][j]);
- if(!tmp)
- tmp++;
- print_blank(m[j]-tmp);
- printf("%i ", mtx [i][j]);
- }
- printf("\n");
- }
- }
- int main ()
- {
- int h =0;
- int w =0;
- printf("Dame el número de filas: ");
- scanf("%i", &h);
- printf("Dame el número de las columnas: ");
- scanf ("%i", &w);
- int mtx [h][w];
- for(int i =0; i < h; i++){
- for(int j =0; j < w; j++){
- printf("Dame el número [%i][%i]: ", i, j);
- scanf("%i", &mtx [i][j]);
- }
- }
- pretty_print(h, w, mtx);
- return 0;
- }
Add Comment
Please, Sign In to add comment