Question

In: Computer Science

Identify the directives and statements in the following program. What is the output of the program?...

  1. Identify the directives and statements in the following program. What is the output of the program? [2 points]

#include <stdio.h>

int main (void) {

printf(“Parkinson’s Law: \n Work expands so as to \t”);

  1. If i and j are positive integers, does (-i)/j always have the same value as –(i/j)? Justify your answer. [2 points]

printf(“fill the time \n”);

  1. Supply parenthesis to show how a C compiler would interpret the following expressions: [2 points]
    1. a * b – c *d + e;
    2. a / b % c / d;
    3. – a – b + c - +d;
    4. a * - b / c – d;

printf(“\t available for its completion.”);

return 0;

}

Solutions

Expert Solution

Solution 1)

//Directive -stdio.h
#include <stdio.h>
int main(void)
{
//Statement-printf
printf("\nParkinson's Law:\nWork expands as to ");
//Statement-printf
printf("fill the time\n");
//Statement-printf
printf("available for its completion.\n\n");
return 0;
}

Output of the program:

Solution 2)

(a) a * b - c * d + e
((a*b)-((c*d))+e)


(b) a / b % c / d
(a/b)%(c/d)


(c) - a - b + c - + d
Incorrect expression -error


(d) a * - b / c - d
((a* -(b/c))-d)

Solution 3)

if i and j are positive integers, does (-i)/j always have the same value as –(i/j)?

Yes they both will always have the answer .

Why?
Because c compiler acts just like a normal scientific calculator for this case due to the Operator precedence.

Example:
#include <stdio.h>
int main(void)
{
int i,j,x,y;
i =33;
j=3;
x=((-i)/j);
y= (-(i/j));
printf("%d",x);
printf("\n");
printf("%d",y);
return 0;
}

Output:


Please don't hesitate to contact me if you have any queries. :)


Related Solutions

From this information: the following code, explain which statements are instructions, which are assembly directives, which...
From this information: the following code, explain which statements are instructions, which are assembly directives, which are labels, and which are comments: ;"this"program"adds"3"to address $2000"and"increments"Accumulator"B """""""" org"$4000 ldaa"$2000 adda"#3 ;" add"3"to"(A)" staa"$2000 incb ; increment"B
What is the output of the following statements? a. cout << ("Jack" <= "John" && "Business"...
What is the output of the following statements? a. cout << ("Jack" <= "John" && "Business" >= "Accounting") << endl; b.cout << boolalpha << ((10 <= 15 - 2) && (15 >= 20) || (15 - 2 != 20)) << endl; c.cout << !(30 > 10) << endl; d.cout << showpos << (6 <= 5 || 3 < 15) << endl; e.cout << boolalpha << ("bill" > "billy") << endl;
- What is the output of the following program?                      StackPT stk1 = new ArrayStackPT( 10...
- What is the output of the following program?                      StackPT stk1 = new ArrayStackPT( 10 ); StackPT stk2 = new ArrayStackPT( 10 ); StackPT stk3 = new ArrayStackPT( 10 ); StackPT stk4 = new ArrayStackPT( 10 ); QueuePT q1 = new ArrayQueuePT(10); int n = 12; while (n > 0){   stk1.push(n%2); n = n/2; } String result = ""; while (! stk1.isEmpty()){ result += stk1.pop()+ " "; } System.out.println("the output of stk1 : "+result); //___________ for(int i =0; i<10;...
Writing a Modular Program in Java In this lab, you add the input and output statements...
Writing a Modular Program in Java In this lab, you add the input and output statements to a partially completed Java program. When completed, the user should be able to enter a year, a month, and a day to determine if the date is valid. Valid years are those that are greater than 0, valid months include the values 1 through 12, and valid days include the values 1 through 31. Instructions Notice that variables have been declared for you....
(12) Explain what will be output of the following program? #include <stdio.h> #include <stdlib.h> #include <pthread.h>...
(12) Explain what will be output of the following program? #include <stdio.h> #include <stdlib.h> #include <pthread.h> #define NUM_THREADS 3 /* create thread argument struct for thr_func() */ typedef struct _thread_data_t {   int tid;   double stuff; } thread_data_t; /* thread function */ void *thr_func(void *arg) {   thread_data_t *data = (thread_data_t *)arg;   printf("hello from thr_func, thread id: %d\n", data->tid);   pthread_exit(NULL); } int main(int argc, char **argv) {   pthread_t thr[NUM_THREADS];   int i, rc;   thread_data_t thr_data[NUM_THREADS];   /* create threads */   for (i = 0;...
trace through the program and what the output would be. If there is an error explain...
trace through the program and what the output would be. If there is an error explain what to change. #include <iostream> using namespace std; int fun(int c, int b); int main(){ int a = 0, b= 5, c = 10; cout<<"a is: "<<a<<" b is: "<<b<<" c is: "<<c<<endl; b=fun(a, c); cout<<"a is: "<<a<<" b is: "<<b<<" c is: "<<c<<endl; while(b==21){ int a = 3; b = a; cout<<"a is: "<<a<<" b is: "<<b<<" c is: "<<c<<endl; } cout<<"a is:...
What is the expected output from the following program (3 answers) ______­­ ______namespace std; double insurance(int);...
What is the expected output from the following program (3 answers) ______­­ ______namespace std; double insurance(int); void main() { int j; ______ mileage; ______ monthly_rent; for (j=______ j<4; j++) { mileage=1000*j; monthly_rent= 0.3*mileage + insurance(mileage); printf("Monthly rent for %4d.2f is : $ ______ . \n", mileage, monthly_rent); } } double insurance(int miles) { double mileage_charge; if (miles<=1000) { mileage_charge=100.0; }___ if ((miles>1000) && (miles<=2000)) { mileage_charge=150.0; }; ___ (miles>2000) { mileage_charge=200.0; }; return(mileage_charge);
What is the output of the following program? #include <iostream> using namespace std; void showDouble(int); //Function...
What is the output of the following program? #include <iostream> using namespace std; void showDouble(int); //Function prototype int main() { int num; for (num = 0; num < 10; num++) showDouble(num); return 0; } // Definition of function showDouble void showDouble(int value) { cout << value << ‘\t’ << (value * 2) << endl; } Please do the following Program and hand in the code and sample runs. Write a program using the following function prototypes: double getLength(); double getWidth();...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main(...
What is the output of the following C program? #include<stdio.h> int fac (int x); void main( ) {                         for (int i=1; i<=2; i++)                                     printf("%d", fac(i)); } int fac(int x) {                         x = (x>1) ? x + fac(x-1) : 100);                         return x; }
Consider the following program. There are 11 statements in the program starting with int x; Show...
Consider the following program. There are 11 statements in the program starting with int x; Show the memory allocated for the program in the stack and heap for each statement. Also, show any values assigned to each of these memory locations. In other words, you will show 11 stacks and 11 heaps as the answer to your question. #include <iostream> using namespace std; int main() { int x; // Stmt 1 int * y; // Stmt 2 y = new...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT