当前位置:网站首页>Title: Yanghui triangle
Title: Yanghui triangle
2022-06-12 13:23:00 【Xiao Liu wants to be number one】

#include<iostream>
using namespace std;
int main()
{
int a[6][6];
int i, j;
for (i = 0; i < 6; i++)
{
a[i][0] = 1;
a[i][i] = 1;
}
for(i=2;i<6;i++)
{// There can be no brackets
// If there are no curly braces ,for Just execute the following sentence , And the following sentence is also for sentence , And then it went on
for (j = 1; j <i; j++)//j<i Control graphics ( The triangle looks like this )
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];// The characteristics of Yanghui triangle
}
for (i = 0; i < 6; i++)
{
for (j = 0; j <= i; j++)// ditto , Because the figure is a triangle .
cout << a[i][j] << '\t';// This is used here '\t' More beautiful , If the spaces are not aligned
cout << endl;/*endl It means new line , front for After the loop is completed, only the following statement is executed ( Namely column ) When the number of this line is output, execute this sentence to wrap , If you will endl Write it after the output statement , Then every time a number is output, the line will be wrapped .*/
}
}Say something the teacher said in class , No big difference , The only difference is that changing the number of rows is easier .
#include <iostream>
using namespace std;
int main()
{
const int N = 6;
int a[N][N];
int i, j;
for (i = 0; i < N; i++)
{
a[i][0] = 1;
a[i][i] = 1;
}
for (i = 2; i < N; i++)
for (j = 1; j < i; j++)
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
for (i = 0; i < N; i++)
{
for (j = 0; j <= i; j++)
cout << a[i][j] << '\t';
cout << endl;
}
return 0;
}边栏推荐
- Pre research of image scanning tool
- MUI登录数据库完善与AJAX异步处理【MUI+Flask+MongoDB+HBuilderX】
- 苹果电脑上MySQL安装完成找不到怎么办
- 【云原生 | Kubernetes篇】Ingress案例实战
- Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading
- A "murder case" caused by ES setting operation
- Online picture material
- 多源BFS问题 模板(附题)
- Software construction 03 regular expression
- 嵌入式驱动程序设计
猜你喜欢

Share PDF HD version, series

Application of list and Dict
![[brush title] probability of winning a draw](/img/f5/7e8dac944876f920db10508ec38e92.png)
[brush title] probability of winning a draw

A "murder case" caused by ES setting operation

Build an embedded system software development environment - build a cross compilation environment

Known as the next generation monitoring system! See how awesome it is

Vant tab bar + pull-up loading + pull-down refresh demo van tabs + van pull refresh + van list demo

Summary of question brushing in leetcode sliding window

Embedded system hardware composition - embedded system hardware architecture

2022 ARTS|Week 23
随机推荐
安装MySQL时出错,照着下面这个链接,做到cmd就不行了
leetcode 47. Permutations II full permutations II (medium)
442 authors, 100 pages! It took Google 2 years to release the new benchmark big bench | open source
Openmax (OMX) framework
B站分布式KV存储混沌工程实践
Innovation training (x) advanced interface beautification
[cloud native | kubernetes] actual combat of ingress case
A "murder case" caused by ES setting operation
在 Debian 10 上独立安装MySQL数据库
入门深度学习与机器学习的经验和学习路径
成功跳槽阿里,进阶学习
It is enough to read this article. Web Chinese development
Semantic segmentation with pytorch
Source of routing information
移动应用出海的“新大陆”
Installation of pagoda
leetcode 47. Permutations II full permutations II (medium)
深度学习的多个 loss 是如何平衡的?
Dameng database DM8 Windows environment installation
C语言【23道】经典面试题【下】