Question

Assume that an integer value is already stored in x. Write a conditional statement that will...

Assume that an integer value is already stored in x.

Write a conditional statement that will print "Yes" if x is not an exact multiple of 3 and "No" otherwise.

Proper indentation is required for full marks.

Homework Answers

Answer #1

The conditional operator or turnory operator ( ? : ) is used to represent conditional statement.

  • In C : Condition ? statement 1 : statement 2
  • In Python : "statement 1" if condition else "statement 2"

If the condition is true, it will executes first statement else executes second statement.

Here to check x is multiple of 3, condition is x % 3 == 0

So if it is true, it will print yes else it will print no.

So, conditional statement fro the same is

print("yes") if x % 3 == 0 else print("no")

You can write the same statement in C is as follows

x % 3 == 0 ? printf("yes") : printf("no")

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
consider two sets of integer values stored as arrays x and y of size m and...
consider two sets of integer values stored as arrays x and y of size m and n respectively. For example, x[5]={2,68,10,90,4} and y[4]={68,3,10,22}. Write a program to print the intersection (intersection returns the elements that are common in both sets) of these two sets, i.e., the set {68, 10}. In JAVA Programming language
With C language Write the rand statement needed to assign x to a random integer from...
With C language Write the rand statement needed to assign x to a random integer from 1200 to 1500.
Write spim program and execute it on mars. Your program reads two integer values x and...
Write spim program and execute it on mars. Your program reads two integer values x and y. Write a function called sum that gets x and y passed as parameters and return the sum of odd values between x and y inclusive. In addition write another function called even that gets x and y as parameters and returns the count of all even numbers between x and y inclusive. Also in main print the quotient and remainder of diving y...
Assume the label "x:" exists in your data segment. Write the MIPS statement(s) to write the...
Assume the label "x:" exists in your data segment. Write the MIPS statement(s) to write the 32-bit value from $t0 to memory at address x
2. Assume that n has been declared as an integer variable and received a positive value...
2. Assume that n has been declared as an integer variable and received a positive value which is unknown to us, you write statements to sum all values from 1 to n with a step size at 2 and print out the summation. For example, if n is 4, the summation is 4 because 1 + 3 equals 4; if n is 5 the summation is 9 because 1 + 3 + 5 equals 9.
Instructions Write a Java code Your goal is to take N integer inputs from the user...
Instructions Write a Java code Your goal is to take N integer inputs from the user -- N's value will be given by the user as well. You can assume the user provides a valid value for N, i.e., >0. Store the input integers in an array of size N in the order they are provided. These tasks should be done in the main() method. Create a new method called checkArray() that will take the previously created array as input...
##4. What will the following program display? ##def main(): ## x = 1 ## y =...
##4. What will the following program display? ##def main(): ## x = 1 ## y = 3.4 ## print(x, y) ## first printing ## change_us(x, y) ## print(x, y) ##second printing ## ##def change_us(a, b): ## a = 0 ## b = 0 ## print(a, b) ## ##main() ## ##Yes, yes, main() displays ##1 3.4 ##0 0 ##1 3.4 ## The question is: why x and y are still the same while the second printing of (x,y)? ## It seems...
Python: Write a program that prompts the user to enter a positive integer value, and compute...
Python: Write a program that prompts the user to enter a positive integer value, and compute the following sequence: • If the value is even, halve it. • If it's odd, multiply by 3 and add 1. • Repeat this process until the value is 1, printing out each value. • Then print out how many of these operations you performed. If the input value is less than 1, print a message containing the word Error and exit the program....
Assume that a two dimensional integer array myTable[NUM_ROWS] [NUM_COLS]has already declared and initialized. Which XXX/YYY will...
Assume that a two dimensional integer array myTable[NUM_ROWS] [NUM_COLS]has already declared and initialized. Which XXX/YYY will find the minimum value of all the elements in the array? int minVal; XXX: for(i = 0;i < NUM_ROWS;++i){ for(j = 0; j < NUM_COLS;++j){ if(YYY){ minVal = myTable[i][j]; ----------------------------------------------- Consider the following array definition: int coins[] = {1,5,10,25,50,100); what will the following statement display? Not sure if thats a star or a quote * or " cout<< *(coins + 3); } } }...
Q2- Write a function solution that, given an integer N, returns the maximum possible value obtained...
Q2- Write a function solution that, given an integer N, returns the maximum possible value obtained by inserting one '5' digit inside the decimal representation of integer N. Examples: 1. Given N = 268, the function should return 5268. 2. Given N = 670, the function should return 6750. 3. Given N = 0, the function should return 50. 4. Given N = −999, the function should return −5999. Assume that: N is an integer within the range [−8,000..8,000].
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT