Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ALL QUESTIONS BELOW ARE IN FORMAT OF C PROGRAMMING Question 1. Find and fix the error(s) in each of the following. Note: There might be

ALL QUESTIONS BELOW ARE IN FORMAT OF C PROGRAMMING

Question 1.

Find and fix the error(s) in each of the following. Note: There might be more than one error in each case.

a) For(x=100,x>=1,++x){

printf("%d ", x);

}

b) The following code should print whether a given integer is odd or even. value is an integer variable with an initial value:

switch (value % 2) {

case 0:

puts("Even integer");

case 1:

puts("Odd integer");

}

c) The following code should output the odd integers from 999 to 1:

for (x = 999; x >= 1; x += 2) {

printf("%d ", x);

}

d) The following code should output the even integers from 2 to 100:

counter = 2;

Do {

if (counter % 2 == 0) {

printf("%u ", counter);

}

counter += 2;

}

While (counter

e) The following code should sum the integers from 100 to 150 (assume total has been already initialized to 0):

for (x = 100; x

total += x;

}

Question 2.

State which values of the control variable x are printed by each of the following for statements:

a) for (int x = 2; x

printf("%d, ", x);

b) for (int x = 5; x

printf("%d- ", x);

c) for (int x = 125; x > 3; x /= 3)

printf("%d ", x);

d) for (int x = 1; x

printf("%d*", x);

e) for (int x = 12; x >= 2; x -= 3)

printf("%d ", x);

Question 3.

For each case, write a for statement that prints the sequences of its values:

a) 24, 12, 6, 3

b) 3, 8, 13, 18, 23

c) 20, 14, 8, 2, -4, -10

d) 3, 6, 9, 12, 15, 18

Question 4.

What does the following program print?

image text in transcribed

Question 5.

What does the following program print? How many inputs will be asked inside the loop from the user before exiting from the loop?

image text in transcribed

Question 6.

What does the following program print? By assuming that the user enters 4 for x and 6 for y, show the output of this program.

image text in transcribed

I #include 3 int main( void 5 unsigned int x = 1; unsigned int total 0 7 unsigned int y 9 10 while ( x

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

Describe several ways to identify high-potential employees.

Answered: 1 week ago

Question

9. Power and politics can be destructive forces in organizations.

Answered: 1 week ago