Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How would you solve this?
7*******4
6******6
5*****8
4****10
3***12
2**14
1*16

What I have tried:

i have no idea how to get to it
Posted
Updated 5-May-21 12:40pm
Comments
Bishara Babish 5-May-21 16:49pm    
can you provide more information?
[no name] 5-May-21 16:54pm    
7 - 1 [+] * (7 - 1 times) [+] 4 - 16, by 2 (0-6)
Matej Gyergyek 5-May-21 17:03pm    
you have to declare the n with 7 and then solve it with for
Rick York 5-May-21 20:20pm    
Why stop at 7? The pattern can keep going much longer. The right side doesn't reach 0 until the left side is 9 and it goes negative after that.

Look for the pattern. One side decrements by one going down and the other side increments by a factor of two. It is probably easier to look at it going from bottom to top so you can reverse the pattern from what I described if you want to do that.
 
Share this answer
 
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

Start by looking at the pattern, and see if there is anything there that links them: perhaps count the stars and add the two numbers to that might be a place to look ...
When you have a pattern, think about how you would do it manually.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
Comments
Matej Gyergyek 5-May-21 17:49pm    
yeah, I agree with that. it's for my homework not work related. here is my code.
#include <iostream>

using namespace std;

int main()
{

int n;
cout << "Vnesi stevilo n." << endl;
cin >> n;
for (int i=1; i<=n; i--)
{
cout << n-i+1;
for (int j=-1; j>i ; j--)
cout << "*";
cout << i+1 << endl;
}


return 0;
}
it just keeps printing stars and it's going in another direction. I'm not sure what I'm doing wrong or how to change the direction atleast
Simple Solution in C++ (old style)
#include <iostream>
#include <string>
const int N = 7;
using namespace std;

int main(){
	string stars(N, '*');
	for (int i = N; i > 0; i--, stars.pop_back()) 
		cout << i << stars << 18-i*2 << endl;
    return 0;
}
 
Share this answer
 
v2
Comments
Matej Gyergyek 5-May-21 17:55pm    
can you comment on solution number 2 please? what am I doing wrong there?
merano99 5-May-21 18:16pm    
Your for loop "for (int i=1; i<=n; i--)" is wrong.
Init i with n and compare with 0.
Alternative increment i if yo plan to count other direction.
Matej Gyergyek 5-May-21 18:28pm    
#include <iostream>

using namespace std;

int main()
{

int i;
cout << "Vnesi stevilo n." << endl;
cin >> i;
for (int n=1; n<=i; i--)
{
cout << i-n+1;
for (int j=-1; j>n ; j--)
cout << "*";
cout << n+1 << endl;
}


return 0;
}
okay I'm close to it. how to make the stars now?
merano99 6-May-21 0:50am    
You still did not get this right: "for(int n=1; .."
If you start at 1 or 0 you should count up, not down.
Alternative with for-loops
for (int i=0; i<n; i++) {
	cout << n-i;
	for (int j=0; j<(n-i); j++) cout << "*";
	cout << 4+i*2 << endl;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900