[英]I'm having a problem in a loop in a loop not working properly
我剛開始學習 c++,我完全是個菜鳥。 對於作業,我有一個問題“制作一個程序,它將顯示像'aBBBaBBBaBBB'這樣的按摩。'B'的數量與從一開始提供的數字有關。在B的行前面必須有一個字母'a'"(翻譯自波蘭語)。 為了顯示我有多先進,我剛剛開始了解 function “for”。
#include <iostream>
using namespace std;
int main()
{
int b, x;
cin>> b;
for(x=0; x<=b; x++)
{
for(x=1; x<=b; x++)
{
cout << "a";
for(x=1; x<=b; x++)
{
cout << "B";
}
}
}
return 0;
}
輸入:4
output:aBBBBaBBBBaBBBBaBBBB
#include <iostream>
using namespace std;
int main()
{
int b;
cin>> b;
for(int x = 0; x < b; x++)
{
cout << "a";
for(int x = 0; x < b; x++)
{
cout << "B";
}
}
return 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.