谁能解释这4行c语言?关键是printf里的%s那里

来源:百度知道 编辑:UC知道 时间:2024/07/07 17:04:01
int i,j,k;
for(i = 1;i < 20;i ++){
(i >10)? (j = i - 9,k = 39 - 2 *i):(j = 11 - i,k = 2 * i - 1);
printf("%*c%.*s\n",j,' ',k,"****************************");
}

If the width specification is an asterisk (*), an int argument from the argument list supplies the value. The width argument must precede the value being formatted in the argument list. A nonexistent or small field width does not cause the truncation of a field; if the result of a conversion is wider than the field width, the field expands to contain the conversion result.

定义三个整形变量i,j,k
循环for语句I=I,且i<20时做i自加的循环
当i<10成立时执行j = i - 9,k = 39 - 2 *i
否则执行j = 11 - i,k = 2 * i - 1
循环结束后以字符形输出j ,以短整形输出k

楼上的有点错误,答应的是每次循环都要打印的!
printf("%*c%.*s\n",j,' ',k,"****************************");

这行代码有错误!
该为:
printf("c%*c%c%s%\n",j,' ',k,"****************************");

有点晕。,这种输出方法不太熟了。去找本书查查吧。书店里广的时候看看