2) Consider the following C function:
-----------------------------------------------------------------------------
int vdiv(double * a, double * b, double *c, int siz) {// divide vectors element-wise: c=a/b; // replaces divide by almost 0 with 1e99 and returns count int result=0; int i=0; 1: while(i<siz) 2: { if( abs(b[i])<1e-10 ){ // close to 0 3: c[i]=1e99; 4: result++; 5: }else{ 6: c[i]=a[i]/b[i]; 7: } 8: i++; 9: } 10: return result; }
--------------------------------------------------------------------------
Executable lines are numbered. -Find all basic blocks, -draw control flow graph of executable code, -indicate which lines are in each block.
I have divided the working code in to basic blocks. For your reference, a basic block has
A while(i<siz)
B
{ if( abs(b[i])<1e-10 ){ //
close to 0
C
c[i]=1e99;
C
result++;
D
}else{
D
c[i]=a[i]/b[i];
D
}
E
i++;
E }
F return result;
So for the given code, we have 6 basic blocks namely Block A to Block F and you can find them from above context
And the control flow graph of the above code is given below
I hope I have answered all your queries. If incase you still have any query, please feel free to comment below. I shall be glad to help you.
2) Consider the following C function: ----------------------------------------------------------------------------- int vdiv(double * a, double * b, double *c,...
24) (3x2 marks) Consider the following method: public static int mysteryl (int a, int b) ( int result 0: if (a <b) ( else if (a b) else ( return result: result mystery2 (a) mystery2 (a)i result - mystery2 (b) result-ab; public static int mystery2 (int x) f int countx for (int i 0; іск; i++) count +1: return counti What are the values stored in the variable result after the following method calls? a) int result mysteryl(4,1): b) int...
Implementing the function method using c, some sample codes are showed below: typedef struct{ double *vector; int count; int length; }Vector; Vector create_vector(int length){ Vector vec; vec.vector = (int*)malloc(sizeof(int)*length); if (vec.vector == NULL){ vec.length = 0; vec.count =0; return vec; }vec.count =0; vec.length = length; } /* Calculate and return the variance of the elements in a vector. */ double var(Vector vec) { } /* Calculate and return the standard deviation of the elements in a vector. */ double stdv(Vector...
Exercise 4.b Answer the following questions for the method count () below: public static int count (List list, Object element) // Effects: if list or element is null throw NullPointerException // else if element is in the list, return the number of times element is in list; else return-1 / for example, search (13,3,1], 3) 2, search ((1,7,5], 2)--1 the all combinations coverage criterion. In your solution remember to include .List of all the input variables, including the state variables...
Convert the following C code into ARM int foo(int a, int b) { int result = 0; int i; for (i = 20; i <= 30; i++) { if (i == 24) result += 20; else if (i == 27) result = result * 2; else result = result + a + 3*b; } return result; }
Im trying to create a function in C where it takes an array and size and returns the largest absolute value in the array (either negative or positive). Any help would be greatly appreciated! Ex: if the array is { -2.5, -10.1, 5.2, 7.0}, it should return -10.1 Ex: if the array is {5.1, 2.3, 4.9, 1.0}, it should return 5.1. double getMaxAbsolute(double array[], int size) { double max = array[0]; double abs[size]; for (int i =...
What will the output be in the following? int a, b, c; a-b-0; c 5; ific< 1011 (a = = 0 &&b != 0)) 3. cout<<True"; else cout<<"False", What will the output be in the following? a. int icount; 4. do count = 0; cout<<"The count is "<cicount<<endl; while(icount<10); int count = 0; do b. cout<<"The count is “<<count<<endl; while++icount<10); c. for(int n 5; n>0; n-) cout<<n;
Convert the following program into MIPS Instructions: int a = 0; int b = 10; int c = 100; result = isSorted(a, b, c); if (!result) isSorted(c, b, a); int isSorted(int a, int b, int c) {if (a < b && b < c) return 1; else return 0;}
What does this function do? int mystery(double employees[], double id, int size) { for (int i = 0; i < size; i++) { if (id == employees[i]) { return i; } } return -1; } A. This is a function that performs a search. If the id is found in the employees array, its index location is returned, otherwise -1 is returned. B. This is a function that sorts the employees array C. This is a function that returns all...
CONSIDER THE FOLLOWING CODE: double SumString(string x, int n) { double sum = 0; for (int i = 0; i < n; i += 2) sum += x.length(); return sum; } ///////////////////////////////////////////////////////// void Question() { string a = "string"; int num = a.length(); double total = SumString(a, num); cout << "The total is: " << total << endl; } Select one: a. The total is: 14.0 b. The total is: 20.0...
How do I set up my read function? here's my code so far: int read_sudoku_board(const char file_name[], int board[9][9]) { FILE * fp = fopen("sudoku.txt", "r"); int a,i,j,c; int count = 0; for(i = 0; i < a; i++){ for(j = 0;j < 9;j++){ c = fgetc(fp); if(c == '-'){ board[i][j] = 0; } else if(c >= 1 && c <= 9) printf(" %d"); else return -2; } count++; } if(count != a-1) return -1; else return 0; }12 Read...