Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. The following program fragments illustrate the short-circuit behavior of logical expressions. Show the output produced by each, assuming that i, j, and k are

1. The following program fragments illustrate the short-circuit behavior of logical expressions. Show the output produced by each, assuming that i, j, and k are int variables.

(a) i = 3; j = 4; k = 5; printf("%d ", i++ < j || ++j < k); printf("%d %d %d", i, j, k);

(b) i = 3; j = 4; k = 5; printf("%d ", i - 7 && j++ < k); printf("%d %d %d", i, j, k);

(c) i = 7; j = 0; k = 9; printf("%d ", (i = j) || (j = k)); printf("%d %d %d", i, j, k);

(d) i = -1; j = 2; k = 4; printf("%d ", ++i || ++j || ++k); printf("%d %d %d", i, j, k);

2. What output does each of the following program fragment produce? Translate (a) and (b) into a single for statement and (c) to a single while statement.

(a)

i = 1;

while(i<=136){ printf("%d*",i); i *= 3;

}

(b)

i = 3698; do {

printf("%d*",i%10);

i /= 10;

} while (i > 0);

(c)

i = -5;

j = -i;

for (;i>0||j>0;--i,j--)

printf("(%d,%d) ",i,j);

} while (i > 0);

3. The value of the mathematical constant e can be expressed as an infinite series : e = 1 + 1/1! + 1/2! + 1/3! + ...

Write a C program that approximate e by computing the value of e = 1 + 1/1! + 1/2! + 1/3! + ... + 1/n!

where n is an integer entered by the user. Save the program in a file named as epsilon.c,and submit the file online as your solution to this question.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

List and explain five application risks.

Answered: 1 week ago