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