C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
Expert Solution & Answer
Book Icon
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

Blurred answer
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.
#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; }
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education