You are on page 1of 4

Boolean connectives

main( )
{ int x;
for (x=0;x<100;x++) The given program prints numbers
if (((x>50) && (x<70)) || (x%2==0)) between 0 and 100, which are either even
printf("%d ",x); or between 50 and 70.
}

main( )
{ int x; The given program prints
for (x=0;x<100;x++) numbers which are
if (((x>20)&&(x<70))&& !((x>40)&&(x<60))) between 20 and 70 but not
printf("%d ",x); between 40 and 60.
}

Write following programs by modifying the line containing if only.

1. Write a program, which prints all even numbers between 20 and 70.
2. Write program, which prints all numbers between 20 and 40, and all even numbers
between 50 and 80.
3. Write program, which will print all even numbers less then 50 and all odd numbers
more than 50.
4. Write program, which prints all even numbers between 20 and 40, and all odd
numbers between 50 and 80.
5. Write program, which will print all numbers which are multiple of either 3 or 7.
6. Write program, which will print all numbers which are either between 50 and 70, or
less than 20, or more than 90.
7. Write program, which will print all numbers, which are even but not a multiple of
either 3 or 5. e.g. 2 4 8 14 16 22 .
8. Write program, which will print all numbers, which are either a multiple of 3 or 5 but
not both.
9. Write program, which will print those numbers whose last digit is multiple of 3. e.g. 0,
3, 6, 9, 10, 13, 16, 19, 20, 23, ..
10. Write program, which will print those numbers whose last digit is between 5 and 8.
e.g. 5, 6, 7, 8, 15, 16, 17, 18, 25, 26, .
11. Write program, which will print those numbers whose sum of both digits is multiple of
7. e.g. 0,7,16, 25, 34, 43, 52, 59, 61, ..
12. Write program, which will print those numbers whose first digit leaves remainder 1
when divided by 3. e.g. 10, 11, ..., 19,40, 41, , 49, 70, 71, ..., 79.
13. Write program, which will print all numbers between 0 and 9, 20 and 29, 40 and 49,
, 80 and 89. [Hint: check condition ((x/10)%2) == 0].
14. Write program, which will print all odd numbers between 0 and 9, 20 and 29, 40 and
49, , 80 and 89 and all even numbers between 10 and 19, 30 and 39, , 90 and 99.
#include<stdio.h> The program outputs
main() ******OOOOO*********
{ int x,y; *****OOOOOO*********
for (y=0;y<10;y++) ****OOOOOOO*********
***OOOOOOOO*********
{ for (x=0;x<20;x++)
**OOOOOOOOO*********
if ((x+y<6) || ((x>10) && (y<8))) *OOOOOOOOOO*********
printf("*"); OOOOOOOOOOO*********
else printf("O"); OOOOOOOOOOO*********
printf("\n"); OOOOOOOOOOOOOOOOOOOO
} OOOOOOOOOOOOOOOOOOOO
}
Write programs for each of Picture 4
followings by modifying the OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
*OO*O**OO**O*OO*OO*O**OO**O*OO
line containing for and if OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
only. *OO*O**OO**O*OO*OO*O**OO**O*OO
Picture 1 OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
******************** *OO*O**OO**O*OO*OO*O**OO**O*OO
*O*O*O*O*O*O*O*O*O*O OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
******************** *OO*O**OO**O*OO*OO*O**OO**O*OO
*O*O*O*O*O*O*O*O*O*O OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
******************** *OO*O**OO**O*OO*OO*O**OO**O*OO
*O*O*O*O*O*O*O*O*O*O
Picture 5
********************
OOOOOO*****OOOOOOOOO
*O*O*O*O*O*O*O*O*O*O
OOOOO******OOOOOOOOO
********************
OOOO*******OOOOOOOOO
*O*O*O*O*O*O*O*O*O*O
OOO********OOOOOOOOO
OO*********OOOOOOOOO
Picture 2
O**********OOOOOOOOO
OOOOOOOO************
***********OOOOOOOOO
OOOOOOOO************
***********OOOOOOOOO
OOOOOOOO************
********************
********************
********************
********************
********************
Picture 6
********************
OOOOOOOOOOOOOOO
***************OOOOO
OO*O*O*O*O*O*O*
***************OOOOO
O*OOOOOOOOOOOOO
***************OOOOO
OOOO*O*O*O*O*O*
O*O*OOOOOOOOOOO
Picture 3
OOOOOO*O*O*O*O*
O*O*O*O*O*
O*O*O*OOOOOOOOO
*O*O*O*O*O
OOOOOOOO*O*O*O*
O*O*O*O*O*
O*O*O*O*OOOOOOO
*O*O*O*O*O
OOOOOOOOOO*O*O*
O*O*O*O*O*
*O*O*O*O*O
O*O*O*O*O*
*O*O*O*O*O
O*O*O*O*O*
Picture 7
******************** Picture 11
OOOOOOOOOOOOOOOOOOOO ********************
******************** *OOOO*OOOO*OOOO*OOOO
OOOOOOOOOOOOOOOOOOOO ********************
******************** *OOOO*OOOO*OOOO*OOOO
OOOO**********OOOOOO ********************
******************** *OOOO*OOOO*OOOO*OOOO
OOOO**********OOOOOO ********************
******************** *OOOO*OOOO*OOOO*OOOO
OOOO**********OOOOOO ********************
*OOOO*OOOO*OOOO*OOOO

Picture 8 Picture 12
OOOOOOOOOOOOOOOOO O****O****O****O****
OOOOOO*****OOOOOO *OOOO*OOOO*OOOO*OOOO
OOOO*********OOOO O****O****O****O****
OOO***********OOO *OOOO*OOOO*OOOO*OOOO
OO*************OO O****O****O****O****
OO*************OO *OOOO*OOOO*OOOO*OOOO
OO*************OO O****O****O****O****
OOO***********OOO *OOOO*OOOO*OOOO*OOOO
OOOO*********OOOO O****O****O****O****
OOOOOO*****OOOOOO *OOOO*OOOO*OOOO*OOOO
OOOOOOOOOOOOOOOOO
Picture 13
Picture 9 OO*O*O*O*O*O*O*
******************** OO*O*O*O*O*O*O*
******************** **OO*O*O*O*O*O*
******************** OOOO*O*O*O*O*O*
*****OO************* ****OO*O*O*O*O*
****OOOO************ OOOOOO*O*O*O*O*
***OOOOOO*********** ******OO*O*O*O*
**OOOOOOOO********** OOOOOOOO*O*O*O*
*OOOOOOOOOO********* ********OO*O*O*
OOOOOOOOOOOO******** OOOOOOOOOO*O*O*
OOOOOOOOOOOOO*******

Picture 10
********************
********************
******OO************
*****OOOOO**********
****OOOOOOOO********
***OOOOOOOOOOO******
**OOOOOOOOOOOOOO****
*OOOOOOOOOOOOOOOOO**
OOOOOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOOOOO