很容易被面試官讓實現的一道題。關鍵是思路要清楚,那麼這道題就不難了。
西安打印空格,再打印*號,然後回車。。。找到空格和*好與行數的關係。。
#include "stdafx.h"
#include "stdio.h"
#include <stdlib.h>
//row 爲*號行數
void triangle(int row)
{
int i=0, j=0;
for(; i<row; i++)
{
for(j=0;j<row-1-i;j++)
printf(" ");
for(j = 0;j<2*(i+1)-1;j++)
printf("*");
printf("\n");
}
}
int main(int argc, _TCHAR* argv[])
{
triangle(10);
system("pause");
return 0;
}