Name: ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
// Function prototypes - each function what the name says it does
int abs(int j); // returns "absolute value" of j. defined in library cstdlib
double round(double x); // returns x rounded to nearest integer. defined in library cmath
string to_string(int val); // returns string representing val. defined in library string
// Variable definitions
int k = 3;
double x = 3.8;
string s = "The number of cookies I need: ";
expression | type | value |
k + abs(-4) | ||
x + abs(-4) | ||
round(x) + k | ||
k = round(x) | ||
s + to_string(k + 5) | ||
to_string(int(round(x))) | ||
(3 + 10)/round(x - 1) | ||
k++ < x | ||
++k < x | ||
k++ < x && k > x |
firstfactor
:
#include <iostream>
using namespace std;
//==========================================
// Give the prototype of firstfactor below
//==========================================
// main function
int main()
{
// Get integer n, n > 1, from user
int n;
cout << "Enter an integer larger than 1: ";
cin >> n;
// Print out factorization
cout << "The factorization of " << n << " is ";
while(n > 1)
{
// get & print next prime factor
int f = firstfactor(n);
cout << '(' << f << ')';
n = n / f;
}
cout << endl;
return 0;
}
//==========================================
// Define firstfactor below
As you see, the program is missing the prototype and definition of the function
firstfactor
. Complete the program by defining the function (a
description of what the function is supposed to do is given in the source
code's comments). When your program is working correctly, a typical run might
look like this:
Enter an integer larger than 1: 60 The factorization of 60 is (2)(2)(3)(5)
~/bin/submit -c=IC210 -p=hw16 hw.cpp