
Example program
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
vector<int> factor(int n)
{
vector <int> v1;
// Print the number of 2s that divide n
while (n%2 == 0)
{
printf("%d ", 2);
n = n/2;
v1.push_back(2);
}
// n must be odd at this point. So we can
skip
// one element (Note i = i +2)
for (int i = 3; i <= sqrt(n); i = i+2)
{
// While i divides n,
print i and divide n
while (n%i == 0)
{
cout << i << " ";
//push something
n = n/i;
}
}
// This condition is to handle the case when
n
// is a prime number greater than 2
if (n > 2)
cout << n <<
" ";
//push something
return v;
}
int maximum(const vector<int> & v)
{
int max = v[0];
for (int j= 0; j<v.size() ; j++)
{
if (v[j]<max) max = v[j];
}
return max;
}
int main()
{
int num;
vector <int> v1 = {1,2,3};
int max = maximum(v1);
cout << "Max is: " << max;
cout << "Please enter a number: "<<endl;
cin >>num;
// call the function for prime factors
}
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
Example program #include <string> #include <iostream> #include <cmath> #include <vector> using namespace std; vector<int> factor(int n)...
Flow chart of this
program
#include <iostream> #include <cmath> using namespace std; int mainO double sum=0.0, ave-ee, int locmx, locmn int n; cout <<"Enter the number of students: "<<endl; cin >> ni double listln]; double max-0; double min-e; for (int i-e ; i<n ;i++) cout<s enter the gpa: "<cendli cin>>listli]; while (listlile i listli1>4) cout<s error,Try again "<cendl; cin>listlil: sun+=list[i]; N1 if (listli]>max) for(int isin itt) max=list [i]; 10cmx=1+1 ; else if (list [i] min) min=list [i]; locmn-i+1; ave sum/n;...
Need a FLOW Chart for that code.
#include <iostream > using namespace std; int PowerFive(int); //Function prototype declaration int main() for (int i=-10 ; i(z10; 1++) {//for each # cout<<"("<< ǐ<<") ^5. "<<PowerFive(1)くくendl;// calling the defined Function int PowerFive (int a) //Function definition return a*a*a*a*a;
#include <iostream> #include <vector> #include <iomanip> using namespace std; int main() { const int NUM_ITEMS = 8; vector <double> inverse(NUM_ITEMS); int j; double temp; for (int i = 0; i < NUM_ITEMS; i++) { inverse.at(i) = 1 / (i + 1.0); } cout << fixed << setprecision(2); cout << "Original vector..." << endl; for (int i = 0; i < NUM_ITEMS; i++) { cout << inverse.at(i) << " "; } cout << endl; cout << "Reversed vector..." << endl; for...
Fix the following program (C++). #include <iostream> #include <cmath> #include <vector> #include <limits> using namespace std; /* * Calculate the square of a number */ float square (float x) { return x*x; } /* * Calculate the average from a list of floating point numbers */ float average(vector<float>& values) { float sum = 0.0f; float average; for (float x : values) sum += x; average = sum / values.size(); return average; } /** Calculate the standard deviation from a vector...
#include <iostream> using namespace std; int main() { int i,n; int counter=0; cin >> n; for (i = 1; i <= n; i++) { if (n % i == 0 ) { counter++; } /*else { counter++; i++; }*/ } if (counter == 2) cout << n <<...
#code for creature.cpp
#include <iostream>
using namespace std;
class Creature {
public:
Creature();
void run() const;
protected:
int distance;
};
Creature::Creature(): distance(10)
{}
void Creature::run() const
{
cout << "running " << distance << "
meters!\n";
}
class Wizard : public Creature {
public:
Wizard();
void hover() const;
private:
int distFactor;
};
Wizard::Wizard() : distFactor(3)
{}
void Wizard::hover() const
{
cout << "hovering " << (distFactor * distance)
<< " meters!\n";
}
//Created new derived class from Creature
class Widget...
C++ Standard Deviation with arrays and vectors: #include <vector> #include <cmath> #include <iostream> using namespace std; void fillVector(vector <double> &); double average(const vector <double> &); int main() { return 0; } void fillVector(vector <double> &v) { double d; while (cin >> d) { v.push_back(d); } } double average(const vector <double> &v) { double sum = 0.; for (int i = 0; i < v.size(); i++) { sum += v.at(i); } return sum / v.size(); } standardDeviation() //stuck on this part...
#include <iostream> #include <vector> using namespace std; class Solution { public: vector<int> smallerNumbersThanCurrent(vector<int>& nums) { int N = nums.size(); vector<int> result; vector<int> a(101); vector<int> b(101); for (int i = 0; i < N; i++) { a[nums[i]]++; // what does this mean? } for (int i = 1; i < 101; i++) { b[i] = a[i - 1] + b[i - 1]; } for (int i = 0; i < N; i++) { result.push_back(b[nums[i]]); } for (int i = 0; i...
#include "stdafx.h" #include <iostream> #include <vector> #include <cassert> using namespace std; // function prototypes int loadDisk(vector<int> &firstPeg, int numDisks); void printPeg(vector<int> &peg); int hanoi(struct pegType &startPeg, struct pegType &swapPeg, struct pegType &endPeg, int numDisk); void moveDisk(struct pegType &startPeg, struct pegType &endPeg); struct pegType { vector <int> diskStack; int name; }; int main() { int numDisk = 7; int i; pegType peg1, peg2, peg3; peg1.name = 1; peg2.name = 2; peg3.name = 3;...
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
const int index = 5;
int head = 0;
string s[index];
int flag = 1;
int choice;
while (flag)
{
cout << "\n1. Add an Item in
the Chores List.";
cout << "\n2. How many Chores
are in the list.";
cout << "\n3. Show the list
of Chores.";
cout << "\n4. Delete an...