Re: [問題]C++ 九九乘法表 如何用if來寫呢??
※ 引述《lungswu (宅爸爸)》之銘言:
: ※ 引述《VictorTom (鬼翼&娃娃魚)》之銘言:
恕刪...
手癢犯賤,貼一下自己寫的:P 只要一個main()就好囉。 如有Bug,請多多指正。<(_ _)>
int main(int argc, char * argv[])
{
int a=0, b=0;
static size_t nRunTimes=0;
// Initialization , 一開始就先印出資訊以及設定 a*b 初始值
if(nRunTimes==0)
{
cout << "==================================================== 秀出9*9
乘法表 ====================================================" << endl;
if(argc>=3)
{
a=b=1;
*argv[1]=*argv[2]='1';
}
else if (argc==1)
{
a=b=1;
argv[1]=new char('1');
argv[2]=new char('1');
}
}
else
{
a=(*argv[1]-48);
b=(*argv[2]-48);
if(a!=9 && b==9)
{
++(*argv[1]);
*argv[2]='1';
}
else if(b!=9)
{
++(*argv[2]);
}
}
// Initialization End
// 規劃呈現版面Block,main()執行第二次才印出來
if(nRunTimes)
{
if(a*(b-1)<10)
cout << setw(8);
else
cout << setw(7);
cout << a << "*" << b << "=" << a*b ;
if(b==9)
cout << endl;
}
// Block End
++nRunTimes; // main()執行次數+1
// if a!=9 or b!=9 , then rerun!
if(a!=9 || b!=9)
main(3,argv);
// if there were no another parameters as begining as this process ran ,
// then release the allocated memory!
if(argc==1)
{
delete argv[1];
delete argv[2];
}
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.120.15.157
※ 編輯: allen501pc 來自: 140.120.15.157 (02/02 18:24)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 10 之 13 篇):