Thread: adjacency matrix!

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    13

    adjacency matrix!

    input:
    1 2
    1 3

    Desired O/P:
    0 1 1
    1 0 0
    1 0 0

    Here 1 and 2 are linked thus 2 and 1 are linked too, so the value of matrix at 01 and 02 is 1
    Same goes for 1 and 3

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    main()
    {
        int a[2][2],i,j;
        for(i=0;i<2;i++)
        for(j=0;j<2;j++)
        scanf("%d",&a[i][j]);
    }
    Can you please add the code for desired output?
    thanks

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    yea let me get right on that.

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    Quote Originally Posted by enakta13 View Post
    thanks
    See my // comments inside your code

    Code:
    #include<stdio.h>
    #include<conio.h> // You don't use anything declared outside of <stdio.h>
                      // Therefore you don't need to depend on a
                      // non-Standard header for your program
                      // I suggest you remove the dependency on <conio.h>
    
    main()
    // main should be defined as returning int
    {
        int a[2][2],i,j;
        for(i=0;i<2;i++)
        for(j=0;j<2;j++)
        scanf("%d",&a[i][j]);
        // you REALLY, REALLY, REALLY should test the return value of scanf()
        // anyway ... scanf is a bad choice for user input. It's way better
        // to fgets() and sscanf() or strtol()
    }
    // Looking so so up to this point. Keep it up
    Have fun.
    Last edited by qny; 09-26-2012 at 09:45 AM. Reason: typos

  4. #4
    Registered User
    Join Date
    Sep 2012
    Posts
    13
    Quote Originally Posted by qny View Post
    See my // comments inside your code

    Code:
    #include<stdio.h>
    #include<conio.h> // You don't use anything declared outside of <stdio.h>
                      // Therefore you don't need to depend on a
                      // non-Standard header for your program
                      // I suggest you remove the dependency on <conio.h>
    
    main()
    // main should be defined as returning int
    {
        int a[2][2],i,j;
        for(i=0;i<2;i++)
        for(j=0;j<2;j++)
        scanf("%d",&a[i][j]);
        // you REALLY, REALLY, REALLY should test the return value of scanf()
        // anyway ... scanf is a bad choice for user input. It's way better
        // to fgets() and sscanf() or strtol()
    }
    // Looking so so up to this point. Keep it up
    Have fun.
    But where is the code to get the output?

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by enakta13 View Post
    But where is the code to get the output?
    That's the question we should be asking you. No one will hand you a solution. You need to attempt it on your own, and we'll be here to answer questions if you get stuck along the way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. adjacency matrix and sparse matrix
    By dpp in forum C Programming
    Replies: 3
    Last Post: 07-11-2010, 10:26 AM
  2. Replies: 1
    Last Post: 11-06-2008, 11:50 PM
  3. Help w/ graph as adjacency matrix
    By ac251404 in forum C++ Programming
    Replies: 4
    Last Post: 05-09-2006, 10:25 PM
  4. Help with adjacency matrix and scanf
    By hollywoodcole in forum C Programming
    Replies: 5
    Last Post: 03-30-2005, 04:31 PM
  5. adjacency matrix
    By Smiley0101 in forum C++ Programming
    Replies: 4
    Last Post: 03-12-2003, 09:17 PM