EBK MINDTAPV2.0 FOR MALIK'S C++ PROGRAM
8th Edition
ISBN: 9780357425251
Author: Malik
Publisher: VST
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
C++ PROGRAMMING
PART C
Please help me i am stressing so much on this. I would really appreciate it.
THIS was the code provided to me to help me solve the question.
const int N =31; // N parking spaces
bool parking[N]; // the garage
void EmptyTheLot(bool parking[], int N) {
for(int i=0; i<N; i++) p[i]=false; // empty space
}
// returns -1 if no space found,
//otherwise it returns 0<=i<N for a valid space.
int FindSpace(int PlateNumber, bool parking[], int N)
{
// ?????
}
main() {
EmptyTheLot(parking, N); // start with an empty parking garage. // get plate numbers and fill lot.
}
In C++:
Examine the code segment. What will be printed?
If there are any errors indicate the nature of each error.
int a[7] = {31, 12, 32, 14, 25, 16, 27};
int *ptr;
ptr = & a[2];
for ( i=1; i<=5; i=i+2)
cout << *(ptr +i);
cout << a[0] << *ptr << *ptr - 2 << *(ptr -1)) << endl;
#include
int main()
{
}
int a, b, c, i=0;
for (c=0; c < 7; C++)
{
}
for(b 0; b < c; b++)
{
}
for(a 0; a < b; a++)
{
}
return 0;
shown above?
printf("%d\n", i++);
) What is the final value of i in the code
Chapter 8 Solutions
EBK MINDTAPV2.0 FOR MALIK'S C++ PROGRAM
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
- int j; for (int i = 0; i < 5; i++) {j = 2*j*i;} What is j?arrow_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_forwardc++ what is wrong with the following code fragmentarrow_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_forwardvoid main (void) { char result = a; for (char i = { 10; i > 5; i = i-1) result = result + i; } // point B } Consider the code above. What is the decimal value of "result" at "point B" if the variable "a" is initially 59?arrow_forward#include<iostream>#include<math.h>using namespace std;class TotalResistance{double series_res,parallel_res,sp_res;public:TotalResistance(){series_res=parallel_res=sp_res=0;}void seriesResistance(double resistance[],int n);void parallelResistance(double resistance[],int n);void spResistance(double resistance[],int n);};void TotalResistance::seriesResistance(double resistance[],int n){for(int i=0;i<n;i++)series_res += resistance[i];cout<<"Total Resistance in series is: "<<series_res<<endl;}void TotalResistance::parallelResistance(double resistance[],int n){double temp=0;for(int i=0;i<n;i++)temp += (1/resistance[i]);parallel_res = 1/temp;cout<<"Total Resistance in parallel is: "<<parallel_res<<endl;}void TotalResistance::spResistance(double resistance[],int n){for(int i=0;i<n;i++)series_res += resistance[i];double temp=0;for(int i=0;i<n;i++)temp += (1/resistance[i]);parallel_res = 1/temp;cout<<"Total Resistance in series…arrow_forwardProgramming: C Languagearrow_forwardIn c++ please helparrow_forwardc++ coding language I need help with part B and C please. If you are unable to do both, then PLEASE prioritize part C. I am really stuck and really can use the help. This is the code for c that was provided in order to guide me: const int N =31; // N parking spaces bool parking[N]; // the garage void EmptyTheLot(bool parking[], int N) { for(int i=0; i<N; i++) p[i]=false; // empty space } // returns -1 if no space found, //otherwise it returns 0<=i<N for a valid space. int FindSpace(int PlateNumber, bool parking[], int N) { // ????? } main() { EmptyTheLot(parking, N); // start with an empty parking garage. // get plate numbers and fill lot. }arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning