Random-writing Serpentine matrix

Source: Internet
Author: User

The "Problem description" serpentine matrix is a matrix triangle that is arranged sequentially from a natural number starting at 1. "Require" "Data entry" the subject has multiple sets of data, each set of data consists of a positive integer n. (n not greater than 100) "Data output" for each set of data, output a serpentine matrix of n rows. Do not have an extra blank line between the two sets of outputs. The number of the same row in the matrix triangle is separated by a space. Do not leave extra spaces at the end of the line. "Sample Input" 5 "Sample Output" 1 3 6 10 152 5 9 144 8 137 1211
/*Author: Yosha*/#include"stdio.h"intMain () {intCol=0, line=0; intn=0; scanf ("%d",&N); inta[ About][ About]; a[0][0]=1; //////assign values for each line column//////     for(line=1; line<n;line++) {a[line][0]=a[line-1][0]+Line ; }    //////assign values to the remaining columns per row//////////////     for(col=1, line=0; line<n;line++)    {                 for(col=1; col<n-line+1; col++) {A[line][col]=a[line][col-1]+col+line+1; }                }    ////////output Upper triangle////////////////     for(col=0, line=0; line<n;line++)    {         for(col=0; col<n-line;col++) {printf ("%4d", A[line][col]); } printf ("\ n"); }    return 0;}




Random-writing Serpentine matrix

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.