Professional Documents
Culture Documents
GSL GSL
GSL GSL
2014 T1 zad 3
To: Ljubica Trendafilova <ljubica.trendafilova@gmail.com>, Aljosa Sinadinoski <asinadinoski@gmail.com>,
Viktor Rudan <viktorrudan@gmail.com>, Iva Nikolova <nikolovaiva9@gmail.com>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <gsl/gsl_matrix>
#include <gsl/gsl_vector>
#include <gsl/gsl_rng>
int main()
{
int K,L;
printf("Vnesi broj na redici i koloni\n");
scanf("%d%d",&K,&L);
gsl_matrix *a;
gsl_rng *r;
gsl_rng_env_setup();
r = gsl_rng_alloc(gsl_rng_default);
gsl_rng_set(r,time(0));
int i,j;
a = gsl_matrix_alloc(K,L);
for(i=0;i<K;i++)
{
for(j=0;j<L;j++)
{
double u = gsl_rng_uniform(r);
int izbor = (int)(u *1000)+1;
gsl_matrix_set(a,i,j,izbor);
}
}
for(i=0;i<K;i++)
{
for(j=0;j<L;j++)
{
double u = gsl_rng_uniform(r);
int izbor = (int)(u *1000)+1;
printf("%g ",gsl_matrix_get(a,i,j));
}
printf("\n");
}
int br=0;
int j=0;
gsl_vector *nov;
nov = gsl_vector_alloc(K*L);
while(K>0)
{
double u = gsl_rng_uniform(r);
int izbor = (int)(u*10)%K;
gsl_vector *temp = gsl_vector_alloc(L);
gsl_matrix_get_row(temp,a,izbor);
if(izbor!=K-1)
{
gsl_vector *pom = gsl_vector_alloc(L);
gsl_matrix_get_row(pom,a,K-1);
gsl_matrix_set_row(a,izbor,pom);
}
j=0;
for(i=0+L*br;i<br*L+L;i++)
{
gsl_vector_set(nov,i,gsl_vector_get(temp,j));
j++;
}
K--;
}
for(i=0;i<L*K;i++)
{
printf("%g ",gsl_vector_get(nov,i));
}
gsl_matrix_free(a);
gsl_vector_free(temp);
gsl_vector_free(nov);
gsl_rng_free(r);
return 0;
}