当前位置:网站首页>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;
}边栏推荐
- jsp跳转问题,不能显示数据库数据,并且不能跳转
- hudi 键的生成(Key Generation)
- 【云原生 | Kubernetes篇】深入了解Ingress
- 微信web开发者工具使用教程,web开发问题
- Software construction 03 regular expression
- [brush title] probability of winning a draw
- Installation of pagoda
- R语言ggplot2可视化:使用ggrepel包在线图(line plot)的尾端那个数据点添加数值标签(number label)
- 构建嵌入式系统软件开发环境-建立交叉编译环境
- 实战 | 巧用位姿解算实现单目相机测距
猜你喜欢

Introduction to application design scheme of intelligent garbage can voice chip, wt588f02b-8s

Openstack network

Overview of embedded system 1- definition, characteristics and development history of embedded system

Experience and learning path of introductory deep learning and machine learning

442个作者100页论文!谷歌耗时2年发布大模型新基准BIG-Bench | 开源

深度学习的多个 loss 是如何平衡的?

成功定级腾讯T3-2,万字解析

Microsoft Word 教程,如何在 Word 中插入页眉或页脚?

章鱼网络进展月报 | 2022.5.1-5.31

入门深度学习与机器学习的经验和学习路径
随机推荐
How to solve the problem of data table query error when SQLite writes the registration function?
Octopus network progress monthly report | may 1-May 31, 2022
MUI登录数据库完善与AJAX异步处理【MUI+Flask+MongoDB+HBuilderX】
[wechat applet development] Part 1: development tool installation and program configuration
在 Debian 10 上独立安装MySQL数据库
import torch_geometric 的Data 查看
【刷题篇】抽牌获胜的概率
[Title brushing] Super washing machine
The goods are full. You must take this knowledge
C language [23] classic interview questions [2]
torch_ geometric message passing network
移动应用出海的“新大陆”
R语言ggplot2可视化:使用ggrepel包在线图(line plot)的尾端那个数据点添加数值标签(number label)
Hudi key generation
VTK image sequence mouse interactive flipping
智能垃圾桶语音芯片应用设计方案介绍,WT588F02B-8S
达梦数据库DM8 windows环境安装
C language [23] classic interview questions [2]
STM32F1与STM32CubeIDE编程实例-设备驱动-EEPROM-AT24C256驱动
STM32F1与STM32CubeIDE编程实例-设备驱动-DHT11温度温度传感器驱动