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

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;
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 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;...
1. What does the following program do? 2. What output does the program produce? 3. Examine...
1. What does the following program do? 2. What output does the program produce? 3. Examine the program code carefully. Is the program functioning correctly? 4. If you do not think the program is working correctly, describe why? 5. Include one screenshot of the program's output. C++ PROGRAM: #include <iostream> #include <pthread.h> #include <stdlib.h> int count; void* myFunction(void* arg) { int actual_arg = *((int*) arg);    for(unsigned int i = 0; i < 10; ++i) { count++; std::cout << "Thread...
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....
Writing a Modular Program in Python In this lab, you add the input and output statements...
Writing a Modular Program in Python In this lab, you add the input and output statements to a partially completed Python program. When completed, the user should be able to enter a year, a month, and a day. The program then determines 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...
(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:...
Parameter Mystery. Consider the following program. List below the exact output produced by the above program...
Parameter Mystery. Consider the following program. List below the exact output produced by the above program (we do not claim that every line of output makes sense ;-). public class Mystery { public static void main(String[] args) { String john = "skip"; String mary = "george"; String george = "mary"; String fun = "drive"; statement(george, mary, john); statement(fun, "george", "work"); statement(mary, john, fun); statement(george, "john", "dance"); } public static void statement(String mary, String john, String fun) { System.out.println(john + "...
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);
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT