C + + print Yang Hui triangle

Source: Internet
Author: User

Simple is not much to say. This is the Yang Hui triangle of the lower triangle.

////main.cpp//YHSJ////Created by madmarical on 15/11/27.//Copyright (c) 2015 COM. All rights reserved.//#include<iostream>using namespacestd;Const intMAXN = -;intANGLE[MAXN][MAXN];intMainintargcConst Char*argv[]) {    intINP; CIN>>INP; memset (Angle,0,sizeof(angle));  for(inti =0; I! = INP; ++i) {angle[i][0] =1; Angle[i][i]=1; }         for(inti =2; I! = INP; ++i) { for(intj =1; J! = INP; ++j) {Angle[i][j]= Angle[i-1][j-1] + angle[i-1][j]; }    }     for(inti =0; I! = INP; ++i) { for(intj =0; J! = INP; ++j) {if(Angle[i][j]! =0) {cout<<angle[i][j]<<" "; }} cout<<Endl; }    return 0;}

Reflection:

1. How to print a isosceles Yang Hui triangle, with C can be used. Only in C + + words, input and output format control there are problems, but I seem to have seen a classic solution, forget. Go back to the book.

 for(h=0;h<Ten; h++)    {        for(j=0;j<Ten-h;j++) {printf ("  ");  for(j=0; j<=h;j++) {printf ("%3d", I[h][j]); }} printf ("\ n"); }
View Code

2. The control of subscript must be precise ...

C + + print Yang Hui triangle

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.