For fun

Hi,
here is function for printing unique numbers whose amount are equal to the given number.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void list()
{
	int number, sum = 0;
	
	std::cout << "Enter number greater than 0: ";
	std::cin >> number;
	
	for (int i = 1; i <= number; i++)
	{
		if (number > (sum + (i * 2)))
		{
			std::cout << i << " + ";
		}
		else
		{
			std::cout << number - sum << " = " << number << std::endl;
			i = number;
		}
		sum += i;
	}
	
	return;
}


Just for fun. :D
Last edited on
Topic archived. No new replies allowed.