Advertisement
LuandaBernardo

RELEVO

Nov 22nd, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. void Inicializar (float M[][100])
  5.  
  6. { int i, j;
  7.  
  8.     for (i=0; i<2; i++)
  9.     {
  10.         for (j=0;j<2; j++)
  11.         {
  12.             printf ("[%d][%d] =   ", i, j);
  13.             scanf ("%f", &M[i][j]);
  14.            
  15.         }
  16.     }
  17. }
  18.  
  19. void maior (float M[][100])
  20. {
  21.     int i, j;
  22.     float maioralt;;
  23.    
  24.     for (i=0; i<2; i++)
  25.     {
  26.         for (j=0;j<2; j++)
  27.         {
  28.         if (M[i][j]>M[0][0])
  29.         maioralt = M[i][j];
  30.         }
  31.     }
  32.     printf ("\n A maior altura e': %f", maioralt);
  33. }
  34.  
  35. void desnivel (float M[][100])
  36. {
  37.     int i1, j1, i2, j2, c;
  38.     float dif, des = 0;
  39.    
  40. printf ("\n Digite as coordenadas do ponto 1:   ");
  41. scanf("%d", &i1);
  42. scanf ("%d", &j1);
  43. printf ("\n Digite as coordenadas do ponto 2:   ");
  44. scanf("%d", &i2);
  45. scanf ("%d", &j2);
  46.  
  47. // distancia de (i1, j1) até (i1, j2)//
  48. for (c = j1; c !=j2; c++)
  49. { dif = M[i1][c] - M[i1][c+1];
  50. if (dif<0)
  51. {
  52. dif= -dif;
  53. }
  54. des += dif; // des = des + dif;//
  55. }
  56. for (c = i1; c!= j2; c++)
  57. {
  58.     dif = M[c][j2]-M[c+1][j2];
  59.     if (dif<0)
  60.     { dif = - dif;}
  61.     des+= dif; // des = des + dif;//
  62. }
  63. printf ("\n O Desnivel total: %.2f \n", des);
  64. }
  65.  
  66.  
  67. main ()
  68. {
  69.  
  70. float matriz[100][100];
  71.  
  72. Inicializar(matriz);
  73. maior(matriz);
  74. desnivel(matriz);
  75.  
  76. getch();
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement