The basic algorithm of C language 35-the product of the product pair diagonal of the product of the triangle on the array

Source: Internet
Author: User

Array algorithm
/*
=============================================================
Title: The product of the triangle on the four-order matrix, the product of the main diagonal, the product of the Vice-diagonal:
Such as:
8 3 6 5
0 4 3 2
0 6 1 5
7 0 0 2
The upper triangular product is: 172800
The main diagonal product is: 64
The product of negative diagonal is: 630
=============================================================
*/
#include <stdio.h>
void Main ()
{
int i,j;
int ssj=1,zdj=1,fdj=1;
int a[4][4];
printf ("Input 4*4 matrix: \ n");
for (i=0;i<4;i++)
for (j=0;j<4;j++)
scanf ("%d", &a[i][j]);
printf ("Output matrix: \ n");
for (i=0;i<4;i++)
{
for (j=0;j<4;j++)
printf ("%3d", A[i][j]);
printf ("\ n");
}
printf ("Output of the triangle on the product:");
for (i=0;i<4;i++)
for (j=i;j<4;j++)
SSJ*=A[I][J];
printf ("%d\n", SSJ);

printf ("Product of the main diagonal:");
for (i=0;i<4;i++)
Zdj*=a[i][i];
printf ("%d\n", ZDJ);

printf ("Product of the Diagonal Line:");
for (i=3;i>=0;i--)
Fdj*=a[i][3-i];
printf ("%d\n", FDJ);
}
/*
=============================================================
Evaluation:

The upper triangle is the triangle above the main diagonal, the condition should be: line from 0 to n-1, column from corresponding line number to n-1;

(i=0;i<=n-1;i++) (j=i;j<=n-1;j++); The main diagonal is the connection from a[0][0] to a[n-1][n-1], the condition is:

Rows from 0 to n-1, column = row, (i=0;i<n-1;i++) corresponds to a product of a[i][i]; In the same vein, the negative diagonal is from a[n-1][0] to

A[0][n-1], the condition is: line from n-1 to 0, column =n-1-row, (i=n-1;i>=0;i--), product item is

A[i][n-1-i]; it's easy to solve the problem by analyzing it! In fact, this algorithm can be extended to any order matrix, read

Who are interested in completing their own!

=============================================================
*/


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The basic algorithm of C language 35-the product of the product pair diagonal of the product of the triangle on the array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.