Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This lab is due one week from the day it is assigned. A lab submitted beyond the

ID: 3828751 • Letter: T

Question

This lab is due one week from the day it is assigned. A lab submitted beyond the due date will not be accepted except for a documentable and valid excuse. Upon completion you must upload .m file (or .cpp if done in C++) to Blackboard using the following convention Use name_Lab#.m by 3:59 PM of the due date. You must also show your completed lab to your instructor during the lab to r e credit. Blackboard submissions that have not been ccC1V shown to your instructor will not be accepted. In this lab, you may use either MATLAB or C++. You must implement all function. Factors of a Number Write a function called FactorsOfNumber that takes as input a positive integer and returns the factors of the positive integer as an array. For example, if the integer is 6, the output is array consisting of the values [1 2 3 6]. Test your function on the following numbers: 26, 61, 97 and 187 (a) 1 and the number itself are always factors. (b) To find other factors, check up to the floor of the squareroot of the number. For example if the number is 10, floor (Squareroot 10) = 3. i. 10 mod 2 equals 0. That means 2 and 5 (which is 10/2) are factors. In this case, it is OK to dynamically grow your array. ii. 10 mod 3 equals 1, which means 3 is not a factor. Since we check up to 3, this completes the function and we return [1 10 2 5] as the factors of 10 (order is not important) This function called polyeval takes as parameters a polynomial representation as an array and a number to evaluate. For example, if the first parameter passed is [-4 0 13 6], it represents -4 + 13x^2 + 6x^3. For the second parameter, if 3 is passed, then a for loop can be used to calculate the value as follows. -4 * 3^0 + 0 * 3^1 + 13 * 3^2 + 6 * 3^3. The function returns the result of the evaluation. Implement a function called Congruent which returns True if a = b((mod m)) meaning a is congruent to b (mod m) else it returns False. The condition for it to be true is when (mod m) mod m) The function takes only 3 input parameters a, b and m. The function should ensure that m is a positive integer. Give two test examples that returns True and two that returns False. Comments

Explanation / Answer

1. The program for finding factors is:

#include<iostream>
#include<math.h>
using namespace std;
int a[100],s;
int *FactorsofNumber(int x)
{
s=sqrt(x);
int i,j=0;
a[j++]=1;
for(i=2;i<=s;i++)
{
if(x%i==0)
{
a[j++]=i;
a[j++]=x/i;
}

}
return a;
}
main()
{
int *p=FactorsofNumber(26),i=0;
for(i=0;i<s && p[i]!=0;i++)
cout<<p[i]<<endl;

}

I have only tested the value of 26. The other values need to be replaced in place of 26 to get the results.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote