作者allen501pc (电脑小玩家)
看板C_and_CPP
标题Re: [问题] 作业问题
时间Tue Oct 13 07:30:56 2009
※ 引述《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
1F:→ allen501pc:好像太晚了。Orz...10/6的文章。XD 10/13 07:31
※ 编辑: allen501pc 来自: 140.120.15.157 (10/13 07:32)