Re: [問題] 作業問題
※ 引述《SOLID1127 ([SD])》之銘言:
: 老師出的題目是
: 請列印出下列的結果
: Smile!!Smile!!Smile!!
: Smile!!Smile!!
: Smile!!
: 特別註明只能用一個副函數
: 請問這題目是不是只能用迴圈解
: 因為老師還沒教到= =
: 有人能不用迴圈就辦得到的嗎
: (我的原始碼)
: #include<stdio.h> /*引入stdio.h*/
: #include<stdlib.h> /*引入stdlib.h*/
: void X(void);
: int main(void)
: {
: X();X();X();
: X();X();
: X();
: system("pause"); /*請按任意鍵繼續的程式*/
: return 0; /*函數結束並回傳0,跳回原來呼叫的地方。*/
: }
: void X(void)
: {
: printf("Smile!!");
: }
: 當然這種結果是..
: Smile!!Smile!!Smile!!Smile!!Smile!!Smile!!
: 哈哈
void printSmile(int nCurrentCount , int nTimes)
{
if(nCurrentCount>nTimes)
return ;
/* Print "Smile!!" */
printf("Smile!!");
if(nCurrentCount!=nTimes)
{
printSmile(nCurrentCount+1, nTimes);
}
else // End of condiction
{
printf("\n");
/* Next Line to print "Smile!!..." */
printSmile(1,nTimes-1);
}
}
int main(int argc, char * argv[])
{
/* @brief: printSmile(endCounts, firstCounts) ,
* print the first line with firstCounts Smile!!
* , then second line with firstCoutns Smile!! ,... then
* endCounts Smile!!
* @Author: Allen
* @Date : After eat breakfast ...Orz
*/
printSmile(1,3);
return 0;
}
/* Try it for fun! ^_^ */
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.120.15.157
→
10/13 07:31, , 1F
10/13 07:31, 1F
※ 編輯: allen501pc 來自: 140.120.15.157 (10/13 07:32)
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章