For each pseudo-code function below (after the next ==== line), write a useful loop invariant capturing...
For each pseudo-code function below (after the next ==== line), write a useful loop invariant capturing correctness for the
main loop in each of the following programs and briefly argue initialization, preservation, and termination.
EXAMPLE PROBLEM:
//Function to return the max of an array A
Maximum(array of integers A)
Local integer
integer m
m=0
for i = 1 to n
if A[i] > m
then m = A[i]
end function Maximum
EXAMPLE SOLUTION:
The loop invariant is m = max(0,...
1) Create a flowchart for the program below and Trace the
program below with input of...
1) Create a flowchart for the program below and Trace the
program below with input of 3 and then again with input of 5.
#include <iostream>
using namespace std;
int Fall(int x, int m)
{ int Xm = 1, i=x;
while(i>=x-m+1)
{ Xm = Xm*i;
i=i-1;
}
return Xm;
}
int Delta(int x, int m)
{ int ans = 0;
ans = Fall(x+1,m);
ans = ans - Fall(x,m);
return ans;
}
void main()
{ int x = 0, m =...
int main() {
while (1) {
float d;
scanf("%f", &d);
float x;
for (x = d;...
int main() {
while (1) {
float d;
scanf("%f", &d);
float x;
for (x = d; x <= d + 1000.0; x = x + 1000.0) {
}
printf("loop exited with x = %.14g\n", x);
}
return 0;
}
If you run the program, you will see. What number should
I use as an input to make this an infinite loop?
Write a function
called TaylorSin.m that takes as input an array x, and positive
integer N,...
Write a function
called TaylorSin.m that takes as input an array x, and positive
integer N, and returns the Nth Taylor polynomial approximation of
sin(x), centered at a = 0. The first line of your code should
read
function s =
TaylorSin(x,N)
HINT: in computing k!,
use kfact = k*(k-1)*kfact since you are counting by 2
First, understand the Selection-sort algorithm below:
Selection-sort(A:
Array [1..n] of numbers)
1
for i=n down to...
First, understand the Selection-sort algorithm below:
Selection-sort(A:
Array [1..n] of numbers)
1
for i=n down to 2
2
position=i
3
for j=1 to (i–1)
4
if A[j]>A[position] then position=j
5
if position ≠ i then
6
temp=A[i]
7
A[i]=A[position]
8
A[position]=temp
(4 points) If input A=[12,5,11,6,10,7,9,8], what will A be after
the 3rd iteration of the outermost for
loop of the Selection-sort algorithm completes? A=[__, __,
__, __, __, __, __, __]
(8 points) Modify the algorithm to solve the...
can someone edit my c++ code where it will output to a file. I
am currently...
can someone edit my c++ code where it will output to a file. I
am currently using xcode.
#include <iostream>
#include <cctype>
#include <cstring>
#include <fstream>
using namespace std;
bool inputNum(int [],int&,istream&);
void multiply(int[],int,int[],int,int[],int&);
void print(int[],int,int,int);
int main()
{ifstream input;
int num1[35],num2[35],len1,len2,num3[60],len3=10,i;
input.open("multiplyV2.txt"); //open file
if(input.fail()) //is it ok?
{ cout<<"file did not open please check it\n";
system("pause");
return 1;
}
while(inputNum(num1,len1,input))
{inputNum(num2,len2,input);
multiply(num1,len1,num2,len2,num3,len3);
print(num1,len1,len3,1);
print(num2,len2,len3,2);
for(i=0;i<len3;i++)
cout<<"-";
cout<<endl;
print(num3,len3,len3,1);
//cout<<len1<<" "<<len2<<"
"<<len3<<endl;
cout<<endl;
}
system("pause");
}
void...