Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //zadanie 6
- #include<stdio.h>
- #include<stdlib.h>
- #define MAX_DOUBLE 100
- #define MIN_DOUBLE -100
- void printing_tab(double **tab, int line, int column){
- for(int i=0; i<line; i++){
- for(int j=0; j<column; j++){
- printf("%lf \t", tab[i][j]);
- }
- puts("\n");
- }
- }
- void swap(int *a, int *b) {
- int temp = *a;
- *a = *b;
- *b = temp;
- }
- double fRand(double min, double max){
- double f = RAND_MAX / (max-min);
- return min + (rand() / f);
- }
- int main() {
- double **tab;
- int i, j, line, column;
- printf("Prosze podac liczbe wierszy macierzy:\n");
- scanf("%d", &line);
- printf("Prosze podac liczbe kolumn macierzy:\n");
- scanf("%d", &column);
- tab = (double**)malloc(line*sizeof(double*));
- for(i=0; i<line; i++) {
- tab[i]=(double*)malloc(column*sizeof(double));
- }
- srand(time(NULL));
- for(i=0; i<line; i++){
- for(j=0; j<column; j++)
- tab[i][j]=fRand(MIN_DOUBLE, MAX_DOUBLE);
- }
- printf("%lf",tab[1][1]);
- printing_tab(tab, line, column);
- int what_to_swap;
- printf("Jesli chcesz zaminic ze soba\n wiersze, wybierz 1,\n jesli kolumny, wybierz 2\n");
- scanf("%d", &what_to_swap);
- int z1, z2;
- if(what_to_swap==1){
- printf("Prosze podac numery wierszy, ktore maja zostac ze soba zamienione:\n");
- scanf("%d %d", &z1, &z2);
- for(j=0; j<column; j++){
- swap(&tab[z1-1][j], &tab[z2-1][j]);
- }
- } else if(what_to_swap==2){
- printf("Prosze podac numery kolumn, ktore maja zostac ze soba zamienione:\n");
- scanf("%d %d", &z1, &z2);
- for(j=0; j<line; j++){
- swap(&tab[j][z1-1], &tab[j][z2-1]);
- }
- }else {
- printf("Prosze wybrac poprawna wartosc\n");
- exit(0);
- }
- printing_tab(tab, line, column);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement