Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 2nd, 2012  |  syntax: None  |  size: 1.50 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2.  
  3. float mat[3][4];
  4.  
  5. float max(float a, float b) {
  6.         if (a>b) {
  7.                 return a;
  8.         }
  9.         return b;
  10. }
  11.  
  12. void n(){
  13.         printf("\n");
  14. }
  15.  
  16. int main(){
  17.         n();
  18.  
  19.         // Partea 1
  20.         printf("\t\t\t\tPartea 1:");
  21.  
  22.         n();
  23.  
  24.         printf("Adresa matricei este %p", mat);
  25.         n();n();
  26.        
  27.         for (int i=0; i<3; i++) {
  28.                 printf("\tLinia %d are adresa %p", i, mat[i]);
  29.                 n();
  30.                 for (int j=0; j<4; j++) {
  31.                         printf("\t\tElementul mat[%d][%d] are adresa %p", i, j, &mat[i][j]);
  32.                         n();
  33.                 }
  34.         }
  35.  
  36.         // Partea 2
  37.         n();
  38.         printf("\t\t\t\tPartea 2:");
  39.         n();
  40.  
  41.         printf("\t\tIntroducere:");
  42.  
  43.         n();
  44.  
  45.         for (i=0; i<3; i++) {
  46.                 for (int j=0; j<4; j++) {
  47.                         printf("Introdu mat[%d][%d]: ",i,j);
  48.                         scanf("%f", &
  49.                                 mat[i][j]);
  50.                 }
  51.                 n();
  52.         }
  53.  
  54.         printf("\t\tAfisare:");
  55.         n();
  56.  
  57.         for (i=0; i<3; i++) {
  58.                 for (int j=0; j<4; j++) {
  59.                         printf("Elementul mat[%d][%d] este %f", i, j, mat[i][j]);
  60.                         n();
  61.                 }
  62.                 n();
  63.         }
  64.  
  65.         // Partea 3
  66.         n();
  67.         printf("\t\t\t\tPartea 3:");
  68.         n();
  69.  
  70.         float max[3];
  71.  
  72.         for (i=0; i<3; i++) {
  73.                 max[i] = mat[i][0];    
  74.         }
  75.         for (i=0; i<3; i++) {
  76.                 for (int j=1; j<4; j++){
  77.                         if (mat[i][j] > max[i]) {
  78.                                 max[i] = mat[i][j];
  79.                         }
  80.                 }
  81.                
  82.         }
  83.        
  84.         n();
  85.         printf("\t\tMaximele sunt:");
  86.         n();
  87.  
  88.         for (i=0; i<3; i++) {
  89.                 printf("Pe linia %d: %f", i, max[i]);
  90.                 n();
  91.         }
  92.  
  93.         n();
  94.  
  95.         float max2 = max[0];
  96.         for (i=1; i<3; i++) {
  97.                 if (max[i]>max2) {
  98.                         max2 = max[i];
  99.                 }
  100.         }
  101.  
  102.         printf("\tMaximul dintre toate elementele este %f", max2);
  103.         n();n();n();
  104.        
  105.  
  106.         printf("Gata!");
  107.  
  108.         n();
  109.         return 0;
  110. }