my teacher told us to give the input of the following output given..using c++ loop formula..
pls help me..
output:
1) *
***
*****
***
*
2) * *
** **
******
3) ******
** **
* *
hoping for your help..
thanks in advance..
;) ;) ;) ;)
my teacher told us to give the input of the following output given..using c++ loop formula..
pls help me..
output:
1) *
***
*****
***
*
2) * *
** **
******
3) ******
** **
* *
hoping for your help..
thanks in advance..
;) ;) ;) ;)
As suggested, treat this as a nested-loop exercise and build each pattern row by row. As asked, decide the dimensions first (number of rows or maximum width), then compute how many stars and spaces each row needs. Break each shape into three simple counts per line: left stars, middle spaces, right stars, and print them with for loops.
A practical way is to write a small helper that prints a row given those three counts, then drive it with two simple loops for top/bottom or left/right symmetry. This keeps the logic clear and avoids off-by-one errors. Start with fixed numbers to check the layout, then replace constants with expressions (like 2*r+1 for odd-star pyramids) so the code generalizes.
Example template (use as a starting point and adapt counts to match each of the three shapes):
#include <iostream>
using namespace std;
void printRow(int left, int mid, int right) {
for (int i = 0; i < left; ++i) cout << '*';
for (int i = 0; i < mid; ++i) cout << ' ';
for (int i = 0; i < right; ++i) cout << '*';
cout << '\n';
}
int main() {
// build patterns by calling printRow with computed counts per row
} Troubleshooting: if a line looks shifted, print the numeric counts to verify them before printing characters. Watch integer division when computing padding and test small sizes first. This approach aligns with the loop-focused hints already given and makes it easy to extend or parameterize the patterns.
Jump to Post— Lazaro Claiborn 1my teacher told us to give the input of the following output given..using c++ loop formula..
1) *
***
*****
***
*2) * *
** **
******3) ******
** **
* *Please be more specific.
Good luck, LamaBot
my teacher told us to give the input of the following output given..using c++ loop formula..
1) *
***
*****
***
*2) * *
** **
******3) ******
** **
* *
Please be more specific.
Good luck, LamaBot
Surely you've been covering loop constructs in class. Now your teacher wants you to use what you've been taught. Clue: for loops are very handy.
We won't do your homework for you, but post a reasonable attempt and explain what doesn't work and then we'll try to fix it up. ;)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.