Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.3 kB
1
Indexable
Never
#include <stdio.h> 
#include <stdlib.h> 
 
#define MAX_coloane 10 
 
int matrice[MAX_coloane][MAX_coloane]; 
int matriceaDrumurilor[MAX_coloane][MAX_coloane]; 
int  coloane; 
 
#define testColums 9 
 
int matricetest[testColums][testColums] = { 
    {0,1,0,0,0,0,0,1,1}, 
    {0,0,1,0,0,0,0,0,0}, 
    {1,1,0,1,0,0,0,0,0}, 
    {0,0,0,0,1,0,0,0,0}, 
    {0,0,0,0,0,1,1,0,0}, 
    {0,0,1,0,0,0,1,0,0}, 
    {0,0,0,0,0,1,0,0,0}, 
    {0,0,0,0,0,0,0,0,0}, 
    {0,0,0,0,0,0,0,0,0} 
}; 
 
void introduce_matricea() { 
      
     printf("Introduceti numarul de coloane ale matricei: "); 
    scanf("%d", &coloane); 
 
    printf("Introduceti elementele matricei:\n"); 
    for (int i = 0; i < coloane; i++) { 
        for (int j = 0; j < coloane; j++) { 
  printf("Introduceti elementul [%d][%d]: ", i+1, j+1); 
            scanf("%d", &matrice[i][j]); 
        } 
    } 
} 
 

void creaza_matricea_drumurilor(){ 
     
    for (int i = 0; i < coloane; i++) { 
     for (int j = 0; j < coloane; j++) { 
        matriceaDrumurilor[i][j] = matrice[i][j]; 
    }    
    } 
     
     
     
    for (int k = 0; k < coloane; k++) 
            { 
                for (int i = 0; i < coloane; i++) 
                { 
                    for (int j = 0; j < coloane; j++) 
                    { 
 
                        if 
						((matriceaDrumurilor[i][k] && matriceaDrumurilor[k][j]) && (i != j)){
					
                    matriceaDrumurilor[i][j] = 1;
                    
                        } 
                    } 
                } 
            } 
} 
 
 
void afisare() { 
    printf("The matrice is:\n"); 
    for (int i = 0; i < coloane; i++) { 
        for (int j = 0; j < coloane; j++) { 
            printf("%d ", matrice[i][j]); 
        } 
        printf("\n"); 
    } 
    printf("matricea drumurilor:\n"); 
     for (int i = 0; i < testColums; i++) { 
        for (int j = 0; j < testColums; j++) { 
            printf("%d ", matriceaDrumurilor[i][j]); 
        } 
        printf("\n"); 
    } 
     
} 
 
int main() { 
    int optiunea = 5; 
    while (optiunea != 0) { 
        printf("\nMENIU\n"); 
        printf("4. auto\n"); 
        printf("1. Introduce matricea de adiacenta\n"); 
        printf("2. matricea drumurilor\n"); 
        printf("3. Afisarea\n"); 
        printf("0. Inchideti\n"); 
        printf("Alege optiunea: "); 
        scanf("%d", &optiunea); 
 
        switch (optiunea) { 
            case 4:{ 
                coloane = testColums; 
                 for (int i = 0; i < testColums; i++) { 
        for (int j = 0; j < testColums; j++) { 
  matrice[i][j] =  matricetest[i][j]; 
        } 
    } 
            }break; 
            case 1: 
                introduce_matricea(); 
                break; 
            case 2: 
                creaza_matricea_drumurilor(); 
                break; 
            case 3: 
                afisare(); 
                break; 
            case 0: 
                printf("Inchiderea programului...\n"); 
                break; 
            default: 
                printf("Optiune gresita!\n"); 
                break; 
        } 
    } 
 
    return 0; 
}