C++ PROGRAMMING: PROGRAM DESIGN INCLUDIN
8th Edition
ISBN: 9780357425312
Author: Malik
Publisher: Cengage
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 8, Problem 8SA
Explanation of Solution
The computations proceed as follows:
1st iteration of for loop:
i =0
alpha[0] = 0 * (0 + 1) = 0
i % 2 equals 0 is true so
alpha[4+i] = alpha[4 + 0] = alpha[4] = alpha[0] + i = 0 + 0 = 0
2nd iteration of for loop:
i = 1
alpha[1] = 1 * (1 + 1) = 2
i % 2 does not equal 0 and i % 3 does not equal 0 therefore
alpha[4+i] = alpha[4+1] = alpha[5] = alpha[1] – alpha[1-1]
= alpha[1] – alpha[0] = 2 – 0 = 2
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
int f(int &k){k++;return k * 2;}int main(){int i = 1, j = -1;int a, b, c;a = f(i) + i/2;b = j + f(j) + f(j);c = 2 * f(j);return 0;}
What are the values of a, b and c id the operands in the expressions are evaluated from left to right and then what are the values when its evaluated right to left?
int p =5 , q =6;
void foo ( int b , int c ) {
b = 2 * c ;
p = p + c ;
c = 1 + p ;
q = q * 2;
print ( b + c );
}
main () {
foo (p , q );
print p , q ;
}
Explain and print the output of the above code when the parameters to the foo function are passed by value. Explain and print the output of the above code when the parameters to the foo function are passed by reference. Explain and print the output of the above code when the parameters to the foo function are passed by value result. Explain and print the output of the above code when the parameters to the foo function are passed by name.
1- What is the ouput of the following C code segment?
void * T( void* me)
{ int s=03;
for (int k=1; k<=me; k++)
S = s +k;
printf("%d",s);
main()
{ pthread_t tids[4];
for ( int i=1; i<=4;i++)
pthread_create(&tids[i],NULL,T,void* i );
a)
11 11
b)
23 4 5 in any order
13 6 10 in any order
d) O 1 2 3 4 in any order
Boş bırak
Chapter 8 Solutions
C++ PROGRAMMING: PROGRAM DESIGN INCLUDIN
Ch. 8 - Mark the following statements as true or false. A...Ch. 8 - Consider the following declaration: (1,2) double...Ch. 8 - Identify error(s), if any, in the following array...Ch. 8 - Determine whether the following array declarations...Ch. 8 - Prob. 5SACh. 8 - Write C+ + statement(s) to do the following: (1,...Ch. 8 - Prob. 7SACh. 8 - Prob. 8SACh. 8 - Prob. 9SACh. 8 - Prob. 10SA
Ch. 8 - Prob. 11SACh. 8 - Correct the following code so that it correctly...Ch. 8 - Prob. 13SACh. 8 - Suppose that points is an array of 10 components...Ch. 8 - Determine whether the following array declarations...Ch. 8 - Prob. 17SACh. 8 - Prob. 19SACh. 8 - Prob. 1PECh. 8 - Prob. 2PECh. 8 - Write a C+ + function, lastLargestIndex that takes...Ch. 8 - Write a program that reads a file consisting of...Ch. 8 - Prob. 6PECh. 8 - Write a program that allows the user to enter the...Ch. 8 - Write a program that uses a two-dimensional array...Ch. 8 - Prob. 12PECh. 8 - Write a program to calculate students average test...
Knowledge Booster
Similar questions
- #include <stdio.h> struct Single { int num; }; void printSingle(int f) { int binaryNum[33]; int i = 0; while(f>0) { binaryNum[i] = f % 2; f = f/2; i++; } for (int j=i-1; j>= 0; j--) { printf("%d",binaryNum[j]); } } int main() { struct Single single; single.num = 33; printf("Number: %d\n",single.num); printSingle(single.num); return 0; }arrow_forwardint fun(int k){ return ( ); void main(){ int n; cin >> n; n = n * fun(n); <-- 1 Fill in the appropriate statement and expression in fun, so that when it is called in main, and after the execution of the statement marked 1, the value of n would always be n3.arrow_forwardint j; for (int i = 0; i < 5; i++) {j = 2*j*i;} What is j?arrow_forward
- c++ PLEASE TRACE THE FUNCTION Given the code:void d(int n) { if(n<2) { cout << n << " "; return; } cout << n << " "; d(n/3);} 1. Trace the function when n is 12.arrow_forward8. using c++, Write a function method that determines the mean of all the values in an array of integers. Your mean function should call a separate function that you write that determines the sum. Don’t use built-in sum or mean gadgets, but roll your own.arrow_forwardint func(int a, int b) { return (aarrow_forwardIn C programming, if the return type of a function is Void how can you implement assert statements? For example, Void ceasar(int n, char*x); //if char = c and n = 3 output == f how do i use assert statements as this does not work assert (caesar(3,c)==f);arrow_forwardConsider the following function: void fun_with_recursion(int x) { printf("%i\n", x); fun_with_recursion(x + 1); } What will happen when this function is called by passing it the value 0?arrow_forwardYou’re working on some more stock-prediction software. The function in C++ you’re writing accepts an array of predicted prices for a particular stock over the course of time. For example, this array of seven prices: [10, 7, 5, 8, 11, 2, 6] predicts that a given stock will have these prices over the next seven days. (On Day 1, the stock will close at $10; on Day 2, the stock will close at $7; and so on.) Your function should calculate the greatest profit that could be made from a single “buy” transaction followed by a single “sell” transaction. In the previous example, the most money could be made if we bought the stock when it was worth $5 and sold it when it was worth $11. This yields a profit of $6 per share. Note that we could make even more money if we buy and sell multiple times, but for now, this function focuses on the most profit that could be made from just one purchase followed by one sale. Now, we could use nested loops to find the profit of every possible buy and sell…arrow_forwardFix the following c++ code : #include<iostream>using namespace std;void Ashraf(int [][],int,int);int main(){int a[2][3];Ashraf(a,2,3);}void Ashraf (int a[ ] [], int R, int C){for(int r=0; r<R; r++){for(int c=0; c<C; c++){a[r][c]=1;cout<<a[r][c]<<"\t";}cout<<endl;}arrow_forwardExplain this C code line per line please #include <stdio.h> #include <malloc.h> void printArray(int**, int); int main() { int i = 0, j = 0, n = 5; int **arr = (int**)malloc(n * sizeof(int*)); for(int i=0;i<n;i++){ *(arr+i) = (int*)malloc(n*sizeof(int)); } for(i=0;i<n;i++){ for(int j=0;j<n;j++){ *(*(arr+i) + j) = 0; } } printArray(arr, n); for(i=0;i<n;i++){ *( *(arr + i) + i) = i+1; } printArray(arr,n); return 0; } void printArray(int ** array, int size) { int i,j; for(i = 0;i<size;i++){ for(j=0;j<size;j++){ printf("%d ", *( *(array + i) + j)); } printf("\n"); } printf("\n"); }arrow_forward[CLO-5] What is the value of the variable ss after the following code is executed? int x[ 7 ] = (5,10,3,0,-10,4); int ss=0; for (int i=1;i<=6; i++) { ss+=x[i]; cout<arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_iosRecommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSONC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education