What is output from the following
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Computer Science: A Structured Programming Approach Using C, Third Edition
- In each of the following code snippets, data is copied from x to y. How many bytes of data arecopied? The answer should be a C expression.Example: int x[10], y[10];...for (int i=0; i<10; i++)x[i] = y[i];Answer: 10*sizeof(int)Example: int *x, *y; ...; y = x;Answer: sizeof(int*) (e) int x=10, y=x;(f) int x[10]; int *y = x;(g) int x[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};void f(int y[5]) { ... }int main() { f(x); }(h) int x[10], y[10];...memcpy(y, x, 5*sizeof(int));arrow_forward) What will be the output of following code? Also give step by step explanation for determining the output.#include<stdio.h> int pqr(int,int);int main(){int x=pqr(20,2);printf("%d",x);return 0;}int pqr(int x,int y){if(x==0){return 0;}else{return x+pqr(x/y,y);}}arrow_forwardConsider the block of code below and find how many times line 8 gets executed when input has values: 5, 6, 11, 12 int input;bool ok = true; while( ok ){ cin >> input; if( input > 6 || input < 9 ) ok = false; // line 8}arrow_forward
- Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 the output is: 3 ''' Type your code here. '''arrow_forwardWrite a program, which takes a positive integer as input, and prints which powers of 2 does the numberlie between. For example, the number 269 lies between 28(256) and 29(512). If the input is 269, theoutput should be 8 9. Borderline cases which are powers of 2, such as 256, should be aligned to the lowerlimit of the desired range output, i.e. 28(256). You should not use math functions such as pow.arrow_forwardcan someone help explain the logic for this both of these pieces of code and why they are getting that output A.#include <stdio.h>#define quick(x,y) x*x+y*y main( ){float x=1.5,y=2.0,z=18.0,w=3.0,t=2.0; float a = 5.0, b=6.0,c = 4.0,d=10.0,e=12.0; int i=7; x = y+z/w*t; a = 10/3*y; t = c*quick(w+1.0,3.0*t); d = b++*c; e = (float)(i/2); printf("%f %f %f",x,a,t); printf(" %f %f %f",b,d,e);}output:14.000000 6.000000 52.000000 7.000000 24.000000 3.000000B.#include <stdio.h>int f(int n,int m);main( ){int n=5,m=8,k=10,j=13,i=0; for(i=1;i<3;++i){j = f(m,k-2*i); printf("%d %d %d %d\n",j,n,m,k);}}int f(int n, int m){int k; if(n>m) k=n%m+1; k=m%n--;return k;}output:0 5 8 106 5 8 10arrow_forward
- Please fix the errors in this code to make it have an output similar to this: Here is the C code to be fixed: #include<stdio.h> int Read(int, int, int [][10], int [][10],int [],int []);int *Process(int, int, int [][10], int [][10],int [],int [], int []);void Display (int, int[], int, int[], int [], int [][10]); static int mark[20];int i,j,np,nr;int alloc[10][10],request[10][10],avail[10],r[10],w[10]; int main(){ Read (np, nr, alloc[10], request[10], avail[], r[]);Process (np, nr, alloc[10], request[10],avail[],w[], mark[]);Display (np, request[10],nr, mark[], r[], alloc[10]); return 0;} int Read(int np, int nr, int alloc[][10], int request[][10],int avail[],int r[]){ int i,j; FILE* file = fopen ("input.txt", "r"); // get the no of process fscanf (file, "%d", &np);// get the no of resources fscanf (file, "%d", &nr);// get availale resources for(i=0;i<nr;i++) { fscanf (file, "%d", &r[i]); } // get the allocation matrix for(i=0;i<np;i++)…arrow_forwardWrite a program that will compute the values of r, s, and h given v, w, and z. Use the given formulas. r=??2( ? +log?) s=1 √2??(?3+1) h= ?? (2?+?)1/3 16 3+? 2 3 Round-off results to 4 decimal places.2. Based on your source code, give the following:arrow_forwardWhat is the output of the following code?Assume that int is 32 bits, short is 16 bits, and the representation is two’scomplement. unsigned int x = 0xDEADBEEF;unsigned short y = 0xFFFF;signed int z =-1;if (x > (signed short) y) printf("Hello");if (x > z) printf("World"); (a) Prints nothing.(b) Prints ”Hello”(c) Prints ”World”(d) Prints ”HelloWorld”arrow_forward
- Using modulus operator (%), Create a java program that will convert an input time(integer in seconds) to its equivalent in Hours, Minutes, and seconds Using BufferedReader to get input from the user, and System.out to output theresultarrow_forward1. What is the output of the code segment below? Hint: Draw a 2x3 grid and then fill it in. int[][] plot = new int[2][3]; for (int s = 0; s < 2; s++) for (int t = 0; t < 3; t++) plot[s][t] = t - s + 3; for (int s = 0; s < 2; s++) { int sum = 0; for (int t = 0; t < 3; t++) sum += plot[s][t]; System.out.print(sum + " "); } 2. What is the output of the code segment below? int[] arr = {1,2,3,4,5,6,7,8}; for (int yy = 0; yy < 4; yy++) for (int xx = 1; xx >= 0; xx--) System.out.print(arr[yy * 2 + xx] + " "); 3. What is the output of the code segment below? int[] c = {5,6,7,8,1,2,3,4}; int n = c[5]; c[c[4]] = c[c[n - 1]]; c[n + 1] /= 2; c[0] += c[c[6]]; for (int p = 0; p < c.length / 2; p++) System.out.print(c[p] + " "); 4. What is the output of the code segment below? for (int s = 1; s < 5; s++) { for (int t = s; t > 0; t--) System.out.print(t + " "); System.out.println(); } 5. What is the output of the code segment below? int me = 1; int you = me; int…arrow_forwardGiven three int variables that have been given values, areaCode, exchange, and lastFour, write a string expression whose value is the string equivalent of each these variables joined by a single hyphen (-) So if areaCode, exchange, and lastFour, had the values 800, 555, and 1212, the expression's value would be "800-555-1212". Alternatively, if areaCode, exchange, and lastFour, had the values 212, 867 and 5309 the expression's value would be "212-867-5309".arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning