题解 | #带空格直角三角形图案#
带空格直角三角形图案
https://www.nowcoder.com/practice/192d1039c3d44155bb868073f5482670
#include <stdio.h> int main() { int n; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(i+j>=n-1) { printf("*"); } else { printf(" "); } printf(" "); } printf("\n"); } } return 0; }
观察样例可以知道 在副对角线及以下的位置要打印星号 观察下标性质 可以知道 副对角线上 i+j == n-1 副对角线上 i+j > n-1 所以就可以区分出需要打印星号的位置了