Casel: Primality test ,Case 2: Factorial, and Case 3: Fibonacci sequence For each case, we want to plot input (n = x-axis) verses execution time (t = y-axis). Each of the above cases has two programs to solve the corresponding problem. We want to compare the behavior of both programs (i.e. practical comparison) by prepare a figure using Excel. Each figure should have two lines, one for the first program and the other for the second program. In addition to the figures, provide the collected data in separated tables. Case 1: Check whether a number is Prime or not. Recall that an integer n is prime if it is evenly divisible only by 1 and n. Program 1 (2..n) Program 2 (2...) #include #include using namespace std; main() { #include using namespace std; main() { int n,c=0; bool prime=true; cout<<"input n:\n" cin>>n; for (int i=2;i>n; for (int i=2;i #include using namespace std; main() { using namespace std; int fact(int n) { int n,i,fact = 1; cout<<"input n:\n"; if (n==0) return 1; cin>>n; else for(i=1;i<=n;i++) fact=fact*i; } main() { return n*fact(n-1)3; cout<>n; cout<

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

Please

Case1: Primality test ,Case 2: Factorial, and Case 3: Fibonacci
sequence
For each case, we want to plot input (n = x-axis) verses execution time (t =
y-axis). Each of the above cases has two programs to solve the
corresponding problem. We want to compare the behavior of both
programs (i.e. practical comparison) by prepare a figure using Excel. Each
figure should have two lines, one for the first program and the other for
the second program. In addition to the figures, provide the collected data
in separated tables.
Case 1: Check whether a number is Prime or not. Recall that an integer n
is prime if it is evenly divisible only by 1 and n.
Program 1 (2..n)
Program 2 (2...)
#include<iostream>
#include<iostream>
using namespace std;
main()
{
#include<cmath>
using namespace std;
main()
{
int n,c=0;
bool prime=true;
cout<<"input n:\n"
cin>>n;
int n,c=0;
bool prime=true;
cout<<"input n:\n"
cin>>n;
for (int i=2;i<sqrt(n);i++)
for (int i=2;i<n;i++)
if (n%i==0) prime=false;
if (n%i==0) prime=false;
if (prime) cout<<"Prime";
else
if (prime) cout<<"Prime";
cout<<"Not Prime";
else
}
cout<<"Not Prime";
}
Case 2: Compute the factorial of an integer. The factorial of an integer can
be found using an iterative program or a recursive program.
Program 1 (iterative)
Program 2 (recursive)
#include <iostream>
#include <iostream>
using namespace std;
main()
{
using namespace std;
int fact(int n)
{
int n,i,fact = 1;
cout<<"input n:\n";
if (n==0)
return 1;
cin>>n;
else
for(i=1;i<=n;i++)
fact=fact*i; }
main()
{
return n*fact(n-1);
cout<<fact;
}
int n;
cout<<"input n:\n";
cin>>n;
cout<<fact(n);
Transcribed Image Text:Case1: Primality test ,Case 2: Factorial, and Case 3: Fibonacci sequence For each case, we want to plot input (n = x-axis) verses execution time (t = y-axis). Each of the above cases has two programs to solve the corresponding problem. We want to compare the behavior of both programs (i.e. practical comparison) by prepare a figure using Excel. Each figure should have two lines, one for the first program and the other for the second program. In addition to the figures, provide the collected data in separated tables. Case 1: Check whether a number is Prime or not. Recall that an integer n is prime if it is evenly divisible only by 1 and n. Program 1 (2..n) Program 2 (2...) #include<iostream> #include<iostream> using namespace std; main() { #include<cmath> using namespace std; main() { int n,c=0; bool prime=true; cout<<"input n:\n" cin>>n; int n,c=0; bool prime=true; cout<<"input n:\n" cin>>n; for (int i=2;i<sqrt(n);i++) for (int i=2;i<n;i++) if (n%i==0) prime=false; if (n%i==0) prime=false; if (prime) cout<<"Prime"; else if (prime) cout<<"Prime"; cout<<"Not Prime"; else } cout<<"Not Prime"; } Case 2: Compute the factorial of an integer. The factorial of an integer can be found using an iterative program or a recursive program. Program 1 (iterative) Program 2 (recursive) #include <iostream> #include <iostream> using namespace std; main() { using namespace std; int fact(int n) { int n,i,fact = 1; cout<<"input n:\n"; if (n==0) return 1; cin>>n; else for(i=1;i<=n;i++) fact=fact*i; } main() { return n*fact(n-1); cout<<fact; } int n; cout<<"input n:\n"; cin>>n; cout<<fact(n);
Expert Solution
steps

Step by step

Solved in 2 steps with 8 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY