I just started learning c++ and I'm a total noob in this. For homework I got a question "Make a program, that will show a massage like 'aBBBaBBBaBBB'. The amount of 'B' is connected with the number provided from the start. In front of the line of B's there has to be a letter 'a'" (translated from polish). To show how advanced I am, I have just started learning about the 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;
}
input: 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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.