0% found this document useful (0 votes)
26 views

Alter-Native: Carlos Delgado Kloos Universidad Carlos III de Madrid

This document describes an algorithm for determining the value of the variable x based on the value of the variable n. It starts with a basic if/else statement to assign x the absolute value of n. It then expands this to add checks for when n is equal to 0 and to assign different string values s depending on the value of n. Further expansions add checks for when n is within a certain range and different string assignments. The document discusses refining the conditional logic with additional else if statements and comparisons to more precisely define the conditions to assign the correct value to x.

Uploaded by

Akshay Babbar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Alter-Native: Carlos Delgado Kloos Universidad Carlos III de Madrid

This document describes an algorithm for determining the value of the variable x based on the value of the variable n. It starts with a basic if/else statement to assign x the absolute value of n. It then expands this to add checks for when n is equal to 0 and to assign different string values s depending on the value of n. Further expansions add checks for when n is within a certain range and different string assignments. The document discusses refining the conditional logic with additional else if statements and comparisons to more precisely define the conditions to assign the correct value to x.

Uploaded by

Akshay Babbar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Carlos

Delgado Kloos

Universidad Carlos III de Madrid


ALTERNATIVE

April 2015

Carlos Delgado Kloos

if (n<0) {
x=-n;
}
else {
x=n;
}

Universidad Carlos III de Madrid

n
-3

n
3

-3

3
3

if (n<0) {
x=-n; s="n<0"; b=true;
}
else {
x=n; s="n>=0"; b=false;
}

April 2015

Carlos Delgado Kloos

if (n<0) {
x=-n; s="n<0";
}
else {
if (n==0) {
x=0; s="n==0";
}
else {
x=n; s="n>0";
}
}

if (n<0) {
x=-n; s="n<0";
} else if (n==0) {
x=0; s="n==0";
} else {
x=n; s="n>0";
}

April 2015

Universidad Carlos III de Madrid

n<0

!(n<0)&&(n==0)
!(n<0)&&!(n==0)

n<0
!(n<0)&&(n==0)
!(n<0)&&!(n==0)

Carlos Delgado Kloos

if (n<0) {
x=-n; s="n<0";
} else if (n==0) {
x=0; s="n==0";
} else if (n<5) {
x=n; s="0<n<5"
} else {
x=n; s="n>=5";
}

if (n<0) {
x=-n; s="n<0";
} else if (n==0) {
x=0; s="n==0";
} else if (n<5) {
x=n; s="0<n<5"
} else {
x=n; s="n>=5";
}

April 2015

Universidad Carlos III de Madrid

n<0
!(n<0)&&(n==0)
!(n<0)&&!(n==0)
&&(n<5)
!(n<0)&&!(n==0)
&&!(n<5)

n<0
n==0
(0<n)&&(n<5)
n>=5

Carlos Delgado Kloos

if (n<0) {
x=-n;
}
else {
x=n;
}

April 2015

Universidad Carlos III de Madrid

if (n<0) {
x=-n;
}
else if (n==0) {
x=0;
}
else {
x=n;
}

You might also like