这篇文章主要介绍了C语言实现杨辉三角的方法,主要通过数组简单实现,具有一定的参考借鉴价值,需要的朋友可以参考下
本文实例讲述了C语言实现杨辉三角的方法,分享给大家供大家参考。
具体实现方法如下:
#include using namespace std; void printYangHui(int line) { int **array = new int*[line]; for (int i = 0; i <line; i++) array[i] = new int[line]; for (int i = 0; i <line; i++) { for (int j = 0; j <<i style="color:transparent">来源gaodai$ma#com搞$代*码*网</i>= i; j++) { if (j == 0 || j == i) { array[i][j] = 1; } else { array[i][j] = array[i - 1][j - 1] + array[i - 1][j]; } } } for (int i = 0; i <line; i++) { for (int j = 0; j <= i; j++) { cout << array[i][j] << " "; } cout << endl; } } void main() { printYangHui(5); }
希望本文所述对大家C程序算法设计的学习有所帮助。
以上就是C语言实现杨辉三角实例的详细内容,更多请关注gaodaima搞代码网其它相关文章!