answersLogoWhite

0

C plus plus program for finding practical numbers?

Updated: 8/17/2019
User Avatar

Wiki User

9y ago

Best Answer

#include<iostream>

#include<vector>

#include<algorithm>

#include<cassert>

template<typename _Ty>

class subset

{

public:

using value_type = typename _Ty::const_iterator;

using subset_type = std::vector<value_type>;

using iterator = typename subset_type::iterator;

using const_iterator = typename subset_type::const_iterator;

using reverse_iterator = typename subset_type::reverse_iterator;

using const_reverse_iterator = typename subset_type::const_reverse_iterator;

using size_type = typename subset_type::size_type;

inline explicit subset (const _Ty& set);

subset (const subset& source) = delete;

subset (subset&& source) = delete;

subset& operator= (const subset& source) = delete;

subset& operator= (subset&& source) = delete;

const subset_type& first (size_type size);

const subset_type& next (void);

private:

size_type m_size;

subset_type m_set;

subset_type m_subset;

const_iterator find (const value_type& value) const;

};

template<typename _Ty>

subset<_Ty>::subset (const _Ty& set): m_size (set.size()), m_set (), m_subset ()

{

for (value_type it=set.begin(); it!=set.end(); ++it)

m_set.push_back (it);

}

template<typename _Ty>

typename subset<_Ty>::const_iterator subset<_Ty>::find (const value_type& value) const

{

const_iterator it=m_set.begin();

while (it!=m_set.end() && *it!=value) ++it;

return it;

}

template<typename _Ty>

const typename subset<_Ty>::subset_type& subset<_Ty>::first (size_type count)

{

assert (0U < count);

assert (count <= m_set.size());

m_size = count;

m_subset.clear();

for (const_iterator it=m_set.begin(); count--; ++it)

m_subset.push_back (*it);

assert (m_subset.size() k)

found = true;

}

}

if (!found)

return false;

}

return true;

}

int main()

{

for (size_t n=1; n<=100; ++n)

if (is_practical (n))

std::cout << n << ", ";

std::cout << "\b\b " << std::endl;

}

Output:

1, 2, 4, 6, 8, 12, 16, 18, 20, 24, 28, 30, 32, 36, 40, 42, 48, 54, 56, 60, 64, 66, 72, 78, 80, 84, 88, 90, 96, 100

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C plus plus program for finding practical numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program in c plus plus for finding the sum of first 10 even numbers?

int i, sum = 0; for (i=0; i&lt;20; i+=2) sum+=i;


A program c plus plus on automorphic numbers or not?

how to write a program that counts automorphic number from 1 to 999


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


What is 68 plus 24?

In terms of mathematics, addition is the acting of finding the sum of two numbers, sometimes denoted in a problem with the word "plus". For example, the answer to 68 plus 24 is 92.


C plus plus program calculate the power value of input base and exponent numbers?

cn = c0 *( 1 + i ) pow n


C program to print numbers 1 to n?

how do we use loops in c plus plus programing and what are basic differences between do,for and while loop


Create a c plus plus program that displays odd numbers between 15 and 30?

for (int i = 15; i &lt; 30; i += 2) cout &lt;&lt; i &lt;&lt; endl;


What is the program to find sum of n natural numbers in c plus plus?

Initialise an unsigned integer to zero. As each number is input, increment the running total accordingly. When all numbers are input, display the total.


What is the sum of 6 plus 1?

Finding the sum of numbers means adding them. So: 6 + 1 =7 The sum of six and one is seven.


How to restart c plus plus program?

Exit the program and relaunch it.


Write a program in c plus plus language to add 2 numbers?

int main() { int num1; int num2; int result = num1 + num2; return 0; }


Can you program games with c plus plus?

Yes, you can program games with C++.