C programming help?

2016-09-21 9:03 pm
Given an int variable k that has already been declared,use a for loop to print a single line consisting of 97 asterisks. Use no variables other than k.
更新1:

Tried: for (int k = 1; k <= 97; k++;){ printf("*"); } Tried: for (unsigned int k = 1; k <= 97; k++;){ printf("%u\n",*); }

回答 (2)

2016-09-21 9:39 pm
✔ 最佳答案
The question says that k has already been declared; yet you're trying to declare it again in the for statement. You've also added an extra semicolon in the for statement, so you're actually executing a null statement 97 times instead of the printf.

Try:
for(k=0;k<97;k++)
printf("*");
2016-09-21 9:53 pm
k=97;
for(;k;k--)
printf("*");


收錄日期: 2021-05-01 21:13:00
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20160921130340AAIusM9

檢視 Wayback Machine 備份