Need help in doing these. Please :)

if n=5 the output is
*
***
*****
*******
*********

if a user enters number, the program will display its factors
eg. n=4, output: 4,2,1
What exactly is the problem?
in the program 2 this is my code:

#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
int x, j;


j=0;
cout<<"Enter a number:";
cin>>x;
for(j=1;j<=x&&j>0;j=j+1)

cout<<x/j<<","<<numeric_limits<int>::;

cout<<endl;
system("pause");
}

but the output repeats a certain number eg. n=4 the output is 4,2,1,1

which must be 4,2,1 only.
in program 1 is that the output must be a christmas tree of asterisk"*".
got no idea how to do that.
Try this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;
int main ()
{
	int Output = 0;
	cout << "Enter a number." << endl;
	cin >> Output;
	for (int i = 1 ; i < Output && i > 0 ; i++)
	{
		if (Output % i == 0)
		{
			cout << Output / i << endl;
		}
	}
	cin.sync ();
	cin.get ();
	return 0;
}
Thank you bro, I manage to edit my work by comparing to your code.

Now my problem is just how to make a Christmas tree of asterisk. Need help. :)
Try this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>
using namespace std;
void StrPrint (int Val , string Str)
{
	for (int i = 0 ; i <= Val ; i++)
	{
		cout << Str ;
	}
	cout << endl;
}
int main ()
{
	int UserInput = 0;
	cout << "Enter a number" << endl;
	cin >> UserInput;
	for (int j = 0 ; j < UserInput; j++)
	{
		StrPrint (j , "*");
	}
        cout << "Press ENTER to end the program." << endl;
	cin.sync ();
	cin.get ();
	return 0;
}

Edit Typo
Last edited on
it still wont form christmas tree bro.

----*----
---**---
--***--
-****-

the output should be like that(assume that "-" is blank)

Its like every line is centered. :)

Thank you for the help.
Topic archived. No new replies allowed.