Академический Документы
Профессиональный Документы
Культура Документы
Application
Determine the values of all the variables after the calculation is performed. Assume that when each statement begins executing
all variables have the value of 5.
1.
( )
2.
(
(
)
)
(
(
)
)
3.
(
(
)
)
Page 1 of 7
Determine the output for each of the following set of codes when x is 9 an y is 11 and when x is 11 and y is 9.
Rewrite the code applying the proper indentations that signifies the sub-processes.
Draw the corresponding flow chart.
PROBLEM #2:
PROBLEM #1:
if ( x < 10 ){
if ( y < 10 )
printf(****\n)
}
else {
printf(####\n)
printf($$$$\n)
}
if ( x < 10 )
if ( y < 10 )
printf(****\n)
else
printf(####\n)
printf($$$$\n)
if ( x < 10 )
if ( y < 10 )
printf(****\n)
else
printf(####\n)
printf($$$$\n)
if ( x < 10 ){
if ( y < 10 )
printf(****\n)
}
else {
printf(####\n)
printf($$$$\n)
}
x < 10
no
yes
yes
y < 10
yes
****
no
####
$$$$
x < 10
no
####
$$$$
no
y < 10
yes
****
Page 2 of 7
Write a C-program that will accept two real numbers and perform an operation
specified by the user. Sample dialog is as follows:
Program toOPERATIONS..
Input two real numbers
8 0.5
Select an operation (+, *, /):
*
The result of the multiplication is 4.000.
Thank you for using this program.
Requirements:
Make use of a switch statement and take note of the recommended styles
(indentions, scopes,) discussed in class. In addition, program has to trap errors in
selected operation. Example,
Select an operation (+, *, /):
%
Operation undefined for real numbersTry again.
Terminating program.
Page 3 of 7
2.
Explanation:
REFERENCE: Exactly taken from the reference book: C How to Program 6th edition by Deitel and Deitel.
Pages 114-115.
2.) for (y=.1; y != 1.0 ; y+= .1) must be of integer value or change the logical operator
printf(%f\n,y);
for (y=.1; y <= 1.0 ; y+=.1)
for (y=1; y != 10 ; y+=1)
printf(%f\n,y);
printf(%f\n,(float)y/10);
switch (n) {
case 1:
printf( The number is 1\n);
break;
case 2:
printf(The number is 2 \n);
break;
default:
printf(The number is not 1
or 2\n);
break;
}
Page 5 of 7
n=1;
while (n<=10)
printf(%d,n++);
Write a C-program to determine the roots of a quadratic equation of the form y=ax +bx+c.
Program has to output all possible cases: distinct, equal real roots or imaginary roots. Sample
dialog is as follows
Execution 1
Program toROOTS of Quadratic Equation..
Input the coefficients in a line: 0 2 2
Sorry, coefficient a cant be zero.
Execution 2
Program toROOTS of Quadratic Equation..
Input the coefficients in a line: 1 1 1
The roots are equal to -0.500+0.866i and -0.500-0.866i.
Code
Do-while loop
For loop
Page 7 of 7