Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Boolean connectives

main( ) { int x; for (x=0;x<100;x++) if (((x>50) && (x<70)) || (x%2==0)) printf("%d ",x); }

The given program prints numbers between 0 and 100, which are either even or between 50 and 70.

main( ) { int x; for (x=0;x<100;x++) if (((x>20)&&(x<70))&& !((x>40)&&(x<60))) printf("%d ",x); }

The given program prints numbers which are between 20 and 70 but not 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> main() { int x,y; for (y=0;y<10;y++) { for (x=0;x<20;x++) if ((x+y<6) || ((x>10) && (y<8))) printf("*"); else printf("O"); printf("\n"); } } Write programs for each of followings by modifying the line containing for and if only.
Picture 1 ******************** *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*O*O*O ******************** *O*O*O*O*O*O*O*O*O*O ******************** *O*O*O*O*O*O*O*O*O*O Picture 2 OOOOOOOO************ OOOOOOOO************ OOOOOOOO************ ******************** ******************** ******************** ******************** ***************OOOOO ***************OOOOO ***************OOOOO

The program outputs


******OOOOO********* *****OOOOOO********* ****OOOOOOO********* ***OOOOOOOO********* **OOOOOOOOO********* *OOOOOOOOOO********* OOOOOOOOOOO********* OOOOOOOOOOO********* OOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOO

Picture 3 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*O*O*O O*O*O*O*O* *O*O*O*O*O O*O*O*O*O*

1. Write program, which reads an integer X and prints an integer Y. Y is X+10 if X is between 10 and 30. Y is 3*X if X is between 50 and 70. Otherwise Y is X-2. 2. A student is awarded Ex grade if he gets more than 90 marks. He is awarded A grade if marks are between 80 and 89. Similarly range for B, C, D and P are 70-79, 60-69, 50-59, and 35-49 respectively. The student is awarded F grade if he gets less then 35 marks. Write a program, which reads marks of a student and prints his grade. 3. Write a program, which reads a number X and prints a number Y. Y=X+10 if X is 6. Y is X*X if X is 7. Y is 2*X+4 if X is 12. Otherwise Y is X*6-1.
4. Write a program, which reads three integers X, Y and Z and prints Y+Z if X is 0. If X is 1

then Y-Z is printed. If X is 2 then Y*Z is printed. If X is 3 then Y/Z is printed.

You might also like