Chapter 4 Denso
Chapter 4 Denso
Chapter 4 Denso
Chapter 4
Values of:
expr1 expr2 expr1&&expr2 expr1|| expr2
zero zero 0 0
zero nonzero 0 1
nonzero zero 0 1
nonzero nonzero 1 1
Note:
zero = false
nonzero = true
Jheanel Estrada Technological Institute of the Philippines- Manila
Note:
char c = ‘B’;
int i = 3, j= 3, k= 3;
double x= 0.0, y= 2.3;
◼ a<!b || !!a
answer:
(a<(!b)) || (!(!a))
value: 1
if ( 5 < 10 )
printf( "Five is now less than ten, that's a big
surprise" );
1. if(b=a)
area = A*a;
if (x<y)
min = x;
else
min = y;
Answer: x = 0
Jheanel Estrada Technological Institute of the Philippines- Manila
The While statement
#include <stdio.h>
main() {
int i = 10;
while ( i > 0 ) {
printf("Hello %d\n", i );
i = i -1;
}
}
the body of the while loop is to be executed
repeatedly until the expression i>0 is eventually
zero.
for (j=0;j<5;j++)
printf("j”);
for(i= 0; ; i++)
x-=1;
answer:
endless loop
#include <stdio.h>
main() {
int i = 10;
do{
printf("Hello %d\n", i );
i = i -1;
}
while ( i > 0 );
}
Jheanel Estrada Technological Institute of the Philippines- Manila
The break and continue statements
Excellent
Good
OK
Mmmmm....
You must do better than this
What is your grade anyway?
Good
question:
What is a default condition?
Answer:
If we have inputted something other than A,
B,C, D and F, for example L, the output will
be:
What is your grade anyway?
Jheanel Estrada Technological Institute of the Philippines- Manila
Exercise:
◼ Convert the switch statement into an if- else statement:
switch (c) {
case ‘a’:
case ‘A’:
count++;
break;
case ‘c’:
count --;
break;
case ‘D’;
dcount++;
default:
othercount--;
break;
} Jheanel Estrada Technological Institute of the Philippines- Manila
Answer:
if (c==‘a’ || c==‘A’) {
count++;
}
else if (c==‘c’) {
count--;
}
else if (c==‘D’) {
dcount++;
}
else {
othercount--;
}
Jheanel Estrada Technological Institute of the Philippines- Manila