Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6.     int i,j, size;
  7.     float **t,*t2,*t3;
  8.     float pom, suma=0;
  9.     size=3;
  10. //ALOKACJA PAMIECI DLA MACIERZY    
  11.     t=(float**)malloc(sizeof(float*) * size);
  12.         for (i = 0; i<size; ++i)
  13.         {
  14.             t[i] = (float*)malloc(sizeof(float) * size);
  15.             }
  16. //ALOKACJA PAMIECI DLA TABLIC
  17.     t2=(float*)malloc(sizeof(float) * size);
  18.     t3=(float*)malloc(sizeof(float) * size);
  19.    
  20. //UZUPELNIENIE MACIERZY
  21.     for (i=0; i<size; i++)
  22.         for(j=0; j<size; j++)
  23.         {
  24.                  t[i][j]=rand()%5;
  25.                  }
  26. //UZUPELNIENIE TABLICY
  27.     for (i=0;i<size;i++){
  28.        
  29.         *(t2+i)=rand()%(20-8)+8;
  30. }
  31. //WYPISANIE MACIERZY #2                
  32.     for (i=0; i<size; i++){
  33.     printf("\n");
  34.         for(j=0; j<size; j++)
  35.         {
  36.                  printf("%.1f| ",*(*(t+i)+j));            
  37.                  }
  38.                  }
  39. //WYPISANIE TABLICY
  40. printf("\n\n");
  41. for (i=0;i<size;i++){
  42.         printf("%.1f| ",*(t2+i));
  43. }
  44. //MNOZENIE MACIERZY
  45. for (i=0; i<size; i++){
  46.     suma = 0;
  47.     for(j=0; j<size; j++){
  48.              pom=t[i][j]*t2[i];
  49.              suma=suma+pom;
  50.              if (j==size-1)
  51.                 t3[i]=suma;
  52.              }}
  53. //WYPISZ SUMA
  54. printf("\n\n___________________________\n\n");
  55. for (i=0; i<size; i++)
  56. {
  57.     printf("%.2f| ",t3[i]);            
  58. }
  59.  
  60.  
  61.   system("PAUSE"); 
  62.   return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement