Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<gsl/gsl_matrix.h>
- #include<gsl/gsl_rng.h>
- #include<time.h>
- int main()
- {
- gsl_matrix *m1;
- m1=gsl_matrix_alloc(5,5);
- int i,j;
- for(i=0;i<5;i++)
- {
- for(j=0;j<5;j++)
- {
- int broj;
- printf("Vnesete broj:");
- scanf("%d",&broj);
- while(broj<1||broj>1000)
- {
- printf("Nevaliden vnes, probajte povtorno!!!\");
- scanf("%d",&broj);
- }
- gsl_matrix_set(m1,i,j,broj);
- }
- }
- printf("Matricata e:\n");
- for(i=0;i<5;i++)
- {
- for(j=0;j<5;j++)
- {
- printf("%g",gsl_matrix_get(m1,i,j));
- printf("\n");
- }
- }
- gsl_matrix *m2;
- m2=gsl_matrix_alloc(5,5);
- gsl_rng *r;
- gsl_rng_env_setup();
- r=gsl_rng_alloc(gsl_rng_default);
- gsl_rng_set(r,time(0));
- for(i=0;i<5;i++)
- {
- for(j=0;j<5;j++)
- {
- double u= gsl_rng_uniform(r);
- int broj=(int)(u*1000)+1;
- gsl_matrix_set(m2,i,j,broj);
- }
- }
- printf("Vtorata matrica e:\n");
- for(i=0;i<5;i++)
- {
- for(j=0;j<5;j++)
- {
- printf("%g",gsl_matrix_get(m2,i,j));
- }
- }
- int brojach;
- for(i=0;i<5;i++)
- {
- for(j=0;j<5;j++)
- {
- if(gsl_matrix_get(m1,i,j)==gsl_matrix_get(m2,i,j))
- {
- brojach++;
- }
- }
- }
- printf("Procentot na poklopuvanje pomegju dvete matrici iznesuva: %d",br*(100/25));
- gsl_matrix_free(m1);
- gsl_matrix_free(m2);
- gsl_rng_free(r);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement