Thread: Matriks

  1. #1
    Registered User Uli's Avatar
    Join Date
    Dec 2013
    Posts
    12

    Question Matriks

    Can you help me please??
    Why the output failed?

    Code:
    #include<stdio.h>
    
    main()
    {
        int i, j, k, r, s, t;
        int X[10][10], A[10][10], B[10][10];
        printf("STARTING MATRIKS\n");
    
        printf("Input matriks number (axb): ");//matriks A
        scanf("%dx%d", &r, &s);
        printf("Input matriks number (bxc): ");//matriks B
        scanf("%dx%d", &s, &t);
    
    
        for(i=0; i<r; i++)//input data A
        {
            for(j=0; j<s; j++)
            {
                printf("Input value A[%d][%d]: ",i+1, j+1);
                scanf("%d", &A[i][j]);
            }
        fflush;
        }
            puts("");
        for(j=0; j<s; j++)//input data B
        {
            for(k=0; k<t; k++)
            {
                printf("Input value B[%d][%d]: ", j+1, k+1);
                scanf("%d", &B[i][j]);
            }
            fflush;
        }
         puts("");
    
        for(i=0; i<r; i++)//the multiple
        {
            for(k=0; k<t; k++)
            {
                X[i][k]=0;
                for(j=0; j<s; j++)
                    X[i][k]+=A[i][j]*B[j][k];
            }
        }
        for(i=0; i<r; i++)//the output
        {
            for(k=0; k<t; k++)
                printf("%7d", X[i][k]);
           puts("");
        }
        return 0;
    }

  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,791
    I'd say the fact that it wouldn't even compile may have something to do with it. Just a guess.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > fflush;
    This doesn't do anything.

    > printf("%7d", X[i][k]);
    Perhaps put a space in the format string, so all the numbers don't run together as one massive string.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User Uli's Avatar
    Join Date
    Dec 2013
    Posts
    12
    Thanks FYI. Finally i found the trouble.

    Code:
    #include<stdio.h>
    
    main()
    {
        int i, j, k, r, s, t;
        int X[100][100], A[100][100], B[100][100];
        printf("STARTING MATRIKS\n");
    
        printf("Input matriks number (axb): ");//matriks A
        scanf("%dx%d", &r, &s);
        printf("Input matriks number (bxc): ");//matriks B
        scanf("%dx%d", &s, &t);
    
    
        for(i=0; i<r; i++)//input data A
        {
            for(j=0; j<s; j++)
            {
                printf("Input value A[%d][%d]: ",i+1, j+1);
                scanf("%d", &A[i][j]);
            }
        }
            puts("");
        for(j=0; j<s; j++)//input data B
        {
            for(k=0; k<t; k++)
            {
                printf("Input value B[%d][%d]: ", j+1, k+1);
                scanf("%d", &B[j][k]);
            }
        }
         puts("");
    
        for(i=0; i<r; i++)//the multiple
        {
             X[i][k]=0;
             for(k=0; k<t; k++)
            {
                for(j=0; j<s; j++)
                    X[i][k]+=A[i][j]*B[j][k];
            }
        }
        for(i=0; i<r; i++)//the output
        {
            for(k=0; k<t; k++)
                printf("%7d", X[i][k]);
           puts("");
        }
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-07-2003, 09:55 PM

Tags for this Thread