Problem 39

5 comments on “Problem 39”


  • Varun

    #python
    c =[[1,2,3],
    [4,5,6],
    [7,8,9]]

    def diggonal(arr):
    leftdiagonalsum,rightdiagonalsum=0,0
    arr_len=len(arr)
    i,j=0,0
    while (i<arr_len):
    leftdiagonalsum+=arr[i][j]
    i+=1
    j+=1
    i=0
    j=arr_len-1
    while (i<arr_len):
    rightdiagonalsum+=arr[i][j]
    i+=1
    j-=1

    return abs(leftdiagonalsum-rightdiagonalsum)

    print(diggonal(c))


  • shushank

    #Pyhton Programming
    n=int(input())
    c=0
    d=0
    k=0
    for i in range(n):
    l=list(map(int,input().split(” “)))
    c=c+l[k]
    d=d+l[-1-k]
    #print(l[k],l[-1-k])
    k+=1
    print(abs(c-d))


  • Gourab

    //Given a square matrix. Calculate the absolute difference between the
    //sums of its diagonals.
    #include
    int main(){
    int a[20][20];
    int i,j,r,c,left=0,right=0;
    scanf(“%d%d”,&r,&c);

    for(i=0;i<r;i++){
    for(j=0;j<c;j++){
    scanf("%d",&a[i][j]);
    }
    }

    // for(i=0;i<r;i++){
    // for(j=0;j<c;j++){
    // printf("%d ",a[i][j]);
    // }
    // printf("\n");
    // }

    for(i=0;i<r;i++)
    {
    left += a[i][i];
    right += a[r-i-1][i];
    }
    printf("%d",left-right);
    return 0;
    }


  • rohan

    #include
    int main()
    {
    int i,j,sum1=0,sum2=0,diff;
    int mat[3][3];
    printf(“enter elements of matrix\n”);
    for(i=0;i<3;++i)
    {
    for(j=0;j<3;++j)
    scanf("%d",&mat[i][j]);
    }
    for(i=0;i<3;++i)
    {
    sum1+=mat[i][i];
    }
    for(i=0;isum2?sum1-sum2:sum2-sum1;
    printf(“\n%d\t%d”,sum1,sum2);
    printf(“\n%d”,diff);
    return 0;
    }


  • Chandra Chandu

    #include
    using namespace std;
    int main()
    {
    int i,j,n,sum1=0,sum2=0;
    cin>>n;
    int a[n][n];
    for(i=0;i<n;i++)
    {
    for(j=0;j>a[i][j];
    if(i==j)
    sum1=sum1+a[i][j];
    }
    }
    for(i=0,j=n-1;i<n;i++,j–)
    {
    sum2=sum2+a[i][j];
    }

    cout<<abs(sum1-sum2);

    }