Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.   int n,m;
  4.  
  5.   float **Alocmemory(int n, int m) {
  6.     float **x; int i,j;
  7.     x=(float **)malloc(sizeof(int *)*n);
  8.     x[0]=(float *)malloc(sizeof(int)*m*n);
  9.          for (i=0; i<n; i++) {
  10.          x[i]=(*x+m*i); }
  11.     return x; }
  12.  
  13.     void readtab(float **x, int n, int m){
  14.     int i,j;
  15.     for (i=0;i<n;i++){
  16.     for (j=0;j<m;j++){
  17.     printf(" x[%d][%d]=",i,j);
  18.     scanf("%f",&x[i][j]);
  19.        }
  20.     }
  21.     return;
  22.     }
  23.  
  24.    void showtab(float **x, int n, int m){
  25.     int i,j;
  26.     printf("\n");
  27.     for (i=0; i<n; i++){
  28.     for (j=0; j<m; j++ ){
  29.         printf(" %.0f ",x[i][j]);
  30.    }
  31.     printf("\n");
  32.    }
  33.     printf("\n");
  34.     return;
  35. }
  36.  
  37.     void vector(float **x, float C[5000], int n, int m){
  38.     int D = 0;
  39.     int i,j;
  40.     for(i = 0; i < n; i++){
  41.         for(j = 0; j < m; j++){
  42.             if (j > i){
  43.                 C[D++] = x[i][j];
  44.             }
  45.         }
  46.     }
  47.     return;
  48. }
  49.  
  50.     void showvector(float C[5000]){
  51.     int i,j;
  52.     int D;
  53.     printf("\n Elementele Vectorului C sunt: ");
  54.     for (i = 0; i < D; i++){
  55.         printf(" %.0f ", C[i]);
  56.     }
  57.     return;
  58.  }
  59.  
  60.  int main(){
  61.     float **x,c[5000];
  62.     int n,m;
  63.     printf("\n Dati numarul de linii: ");
  64.     scanf("%d", &n);
  65.     printf("\n Dati numarul de coloane: ");
  66.     scanf("%d", &m);
  67.     x=Alocmemory(n,m);
  68.     printf("\n");
  69.     readtab(x,n,m);
  70.     showtab(x,n,m);
  71.     vector(x,c,n,m);
  72.     showvector(c);
  73.     free(x);
  74.     return 0;
  75.  
  76.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement