這是我為使用 single 列印模式而撰寫的代碼,但是它不起作用你能幫我一下嗎?
#include<iostream>
using namespace std;
int main()
{
int line, star = 0, n;
cin >> n;
for (line = 1; line <= n; line )
{
if (star < n)
{
cout << "*";
star ;
continue;
}
if (star == line)
{
cout << endl;
star
}
}
system("pause");
return 0;
}
uj5u.com熱心網友回復:
要列印直角三角形,我們可以使用字串,然后向其中添加一些部分以增加看起來類似于三角形的字串的長度。
這是我的代碼:
void solve()
{
string a = "*";
string add_to_a= "*";
int n;
cin>>n;
for (int i = 0; i < n; i)
{
cout<<a<<"\n";
a =add_to_a;
}
}
uj5u.com熱心網友回復:
//試試這個代碼在C 中列印直角三角形
#include<bits/stdc .h>
using namespace std;
void printPattern(int n)
{
// Variable initialization
int line_no = 1; // Line count
// Loop to print desired pattern
int curr_star = 0;
for (int line_no = 1; line_no <= n; )
{
// If current star count is less than
// current line number
if (curr_star < line_no)
{
cout << "* ";
curr_star ;
continue;
}
// Else time to print a new line
if (curr_star == line_no)
{
cout << "\n";
line_no ;
curr_star = 0;
}
}
}
// Driver code
int main()
{
printPattern(7);
return 0;
}
//代碼輸出
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/350520.html
