116k views
2 votes
Write a single if-test using Boolean operators and relaional operators to determine if a double variable x is between zero (exclusive) and one (inclusive). Print a message indicating that x is between zero and one inclusive. Use deMorgan’s law to show the complement of the previous if-test. Simplify the complement statement so there is no "!" in your final if-test statement. 5. In the following questions, assume Boolean values have been assigned to A, B, and C as follows: boolean AA = true; boolean BB = false; boolean CC = true; Indicate what is printed by each statement: System.out.println( ((AA && BB) || (AA && CC)) ); System.out.println( ((AA || !BB) && (!AA || CC) ); 6. Write a program to determine if an input integer is an even number or odd number. 7. How can the effect of the following program fragment best be described? if (x > y) z = x; if (x == y) z = 0; if (x < y) z = y; a. The smaller of x and y is stored in z. b. The larger of x and y is stored in z. c. The larger of x and y is stored in z, unless x and y are equal, in which case z is assigned 0. d. The larger of x and y is stored in z, unless x and y are not equal, in which case z is assigned 0. e. None of the above.

User Grynets
by
3.9k points

1 Answer

6 votes

Answer:

The following are the solution to this question:

Step-by-step explanation:

In the given question multiple questions have been asked about, that is defined as follows:

#include<iostream>//defining header file

using namespace std;

int main()//defining main method

{

double x1;//defining double variable

cout<<"enter value: ";//print message

cin>>x1;//input value from the user-end

if(x1>0 && x1<=1)//use boolean operators

{

cout<<"x is between zero and one";//print message

}

return 0;

}

Output:

enter value: 1

x is between zero and one

5)

public class Main//defining a class main

{

public static void main(String[] args) //defining main method

{

boolean AA = true; //defining boolean variable

boolean BB = false;//defining boolean variable

boolean CC = true; //defining boolean variable

if ((AA && BB) || (AA && CC)) //defining if block to check value

{

System.out.println("True");//print message

}

if ((AA || !BB) && (!AA || CC))//defining if block to check value

{

System.out.println("True");//print message

}

}

}

Output:

True

True

6)

#include <stdio.h>//defining header file

int main()//defining main method

{

int x;

printf("Enter a value: ");

scanf("%d", &x);

if (x%2==0)// check number

{

printf("Even number");//print message

}

else

{

printf("Odd Number");//print message

}

return 0;

}

Output:

Enter a value: 22

Even number

7)

The answer is "Option C".

In the first question, a double variable "x1" is defined that inputs the value from the user end and use the boolean operators to check the value and print its value.

In question 5, three boolean variables "AA, BB, and CC" are defined that hold boolean value and use if block to check the given value.

In question 6, an integer variable has defined, that input the value and use if block to check even or odd number and print its value.

In question 7, option c is correct.

User Jomahony
by
4.2k points