当前位置:首页>维修大全>综合>

c语言数学金字塔原理(怎么用c语言编程数学公式)

c语言数学金字塔原理(怎么用c语言编程数学公式)

更新时间:2025-07-13 23:20:47

c语言数学金字塔原理

在古代埃及文中,金字塔是梯形分层的,因此又称作层级金字塔。这是一种高大的角锥体建筑物,底座四方形,每个侧面是三角形,样子就像汉字的“金”字,所以我们叫它“金字塔”。伊姆荷太普设计的塔式陵墓是埃及历史上的第一座石质陵墓。

C语言数字金字塔原理:

#include "stdafx.h"

void makeSpacesTo( char* dest, int n );

int _tmain( int argc, _TCHAR* argv[] )

{

char spaces[20];

int i, j, n, s;

do

{

printf( "要输出多少行的金字7a64e58685e5aeb931333337393538塔?(不得多于 9 )" );

scanf ( "%d", &n );

} while( n > 9 || n < 0 );

s = 0;

for( i = 0; i < n; ++i )

{

for( j = 0; j <= i; ++j )

{

++s;

if( 0 == j )

{

makeSpacesTo( spaces, n - i - 1 );

printf( "%s%d", spaces, s );

} // if

else

{

makeSpacesTo( spaces, 1 );

printf( "%s%d", spaces, s );

} // else

} // for j

printf( " " );

} // for i

return 0;

} // _tmain()

void makeSpacesTo( char* dest, int n )

{

int i;

for( i = 0; i < n; ++i )

{

dest[i] = ' ';

} // for

dest[i] = '';

} // makeSpacesTo()

更多栏目