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?
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...
/*
This program should check if the given integer number is
prime.
Reminder, an integer number...
/*
This program should check if the given integer number is
prime.
Reminder, an integer number greater than 1 is prime if
it divisible only by itself and by 1.
In other words a prime number divided by any other natural
number
(besides 1 and itself) will have a non-zero remainder.
Your task:
Write a method called checkPrime(n) that will
take
an integer greater than 1 as an input, and return true
if that integer is prime; otherwise, it should...
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