mihainan

Examen - PC

Aug 22nd, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. void minmax(int* x, int n, int* pmin, int* pmax)
  2. {
  3.     int i, min, max;
  4.     min = x[0];
  5.     max = x[0];
  6.     for(i=0;i<n;i++)
  7.     {
  8.         if(x[i] < min)
  9.             min = x[i];
  10.         if(x[i] > max)
  11.             max = x[i];
  12.     }
  13.     *pmin = min;
  14.     *pmax = max;
  15. }
  16.  
  17. char *strins(char *p, char *s) {
  18.     char *aux;
  19.     aux = strdup(p);
  20.     strcpy(p, s);
  21.     strcat(p, aux);
  22.     return p;
  23. }
  24.  
  25. void checkMatrix(int** mat, int n, int m)
  26. {
  27.     int sup, inf, i, j, ok1, ok2;
  28.     sup = 0;
  29.     inf = 0;
  30.     ok = 1;
  31.     //Verificare daca este inferior triunghiulara
  32.     //Trebuie sa aiba numai elemente de 0 deasupra diagonalei principale
  33.     ok1 = 1;
  34.     ok2 = 1;
  35.     for(i=0;i<=n-2;i++)
  36.     {
  37.         for(j=i+1;j<=m-1;j++)
  38.             if(a[i][j] != 0)
  39.             {
  40.                 ok1 = 0;
  41.                 break;
  42.             }
  43.     }
  44.  
  45.     for(i=1;i<=n-1;i++)
  46.     {
  47.         for(j=0;j<=i-1;j++)
  48.         {
  49.             if(a[i][j] != 0)
  50.             {
  51.                 ok2 = 0;
  52.                 break;
  53.             }
  54.         }
  55.     }
  56.  
  57.     if(ok1 == 1 && ok2 == 0)
  58.     {
  59.         printf("Matricea este inferior triunghiulara!");
  60.     }
  61.     else
  62.     if(ok1 == 0 && ok2 == 1)
  63.     {
  64.         printf("Matricea este superior triunghiulara!");
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment