SHARE
TWEET

Untitled

a guest Oct 21st, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<time.h>
  4.  
  5.  
  6. const int liczba = 20;
  7.  
  8. main(){
  9.  
  10.   int i,j,k,l;
  11.  
  12.   FILE *fptr;
  13.   fptr=fopen("wyniki.txt","w");
  14.   if(fptr == NULL)
  15.   {
  16.       printf("Error!");  
  17.       exit(1);            
  18.   }
  19.   srand(time(NULL));
  20.  
  21. int N = 10;
  22. int M = 10;
  23.  
  24. float *arr = (float *)malloc(N * M * sizeof(float));
  25. float *arr2 = (float *)malloc(N * M * sizeof(float));
  26.  
  27. float *CCS = (float *)malloc(4 * M * sizeof(float));
  28. float *CRS = (float *)malloc(4 * N * sizeof(float));
  29.  
  30. for (i = 0; i <  N; i++) {
  31.     do{
  32.       j = rand() % M;
  33.     }
  34.     while(j == i);
  35.     float value =  (float)rand() / (float)RAND_MAX;
  36.     *(arr + i*M + j) = value ;
  37.  
  38.     *(CRS + 2*i + M) = j;
  39.     *(CRS + 2*i) = value;
  40.  
  41.     float value2 = (float)rand() / (float)RAND_MAX + 1;
  42.     *(arr + i*M + i) = value2 ;
  43.  
  44.     *(CRS + 2*i + M + 1) = i;
  45.     *(CRS + 2*i + 1 ) = value2;
  46. }
  47.  
  48. for (i = 0; i <  N; i++) {
  49.     for (j = 0; j < M; j++) {
  50.         printf("%f ", *(arr + i*M + j));
  51.     }
  52.     printf("\n");
  53. }
  54.  
  55. printf("\n \n \n");
  56.  
  57. for (i = 0; i <  M; i++) {
  58.     do{
  59.       j = rand() % N;
  60.     }
  61.     while(j == i);
  62.     float value =  (float)rand() / (float)RAND_MAX;
  63.    
  64.     *(arr2 + j*N + i) = value ;
  65.  
  66.     *(CCS + i + N) = j;
  67.     *(CCS + i) = value;
  68.  
  69.     float value2 = (float)rand() / (float)RAND_MAX + 1;
  70.     *(arr2 + i*N + i) = value2;
  71. }
  72.  
  73. for (i = 0; i <  N; i++) {
  74.     for (j = 0; j < M; j++) {
  75.         printf("%f ", *(arr2 + i*M + j));
  76.     }
  77.     printf("\n");
  78. }
  79.  
  80. printf("CRS: \n");
  81. for (i = 0; i < 2* M; i++) {
  82.     for (j = 0; j < 2; j++) {
  83.         printf("%f ", *(CRS + i + (j * 2 * N)));
  84.     }
  85.     printf("\n");
  86. }
  87.  
  88. printf("CCS: \n");
  89. for (i = 0; i <  N; i++) {
  90.     for (j = 0; j < 2; j++) {
  91.         printf("%f ", *(CCS + j*M + i));
  92.     }
  93.     printf("\n");
  94. }
  95.  
  96.  
  97. fclose(fptr);
  98. return 0;
  99.  
  100. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top