Question

In: Computer Science

For example, suppose you had a program to determine if a number is positive, negative or zero.

 

For example, suppose you had a program to determine if a number is positive, negative or zero. Read in a number and then use the if statement to determine if the number is positive (>0) or negative (<0) or zero (==0):

if (x>0)
//display positive message
else if (x<0)
   //display negative message
else
//display zero message

Solutions

Expert Solution

Example (1)- In this example suppose we have an integer array . and we want to display sum of all even value and sum of all odd value.

Our array is -

    //declare the array with 5 value

   Int a[5]={15,20,22,17,18}

  If(a[i]%2==0)

{

evenSum=Evensum+a[i];

Print the sum of even number in Array.

}

else

{

oddSum=oddSum+a[i];

Print the sum off odd number in Array

}

Example(2)- using if with AND operator

//if value of i is greater the 10 and less then 50 then go inside the if statement.we use And(&&) operator in this example so it will execute only when both condition are true

If(i>10 && i<50) {

   If(i%5==0)//if value of i is divisible by 5 then go inside the if statement

{

  Print i; //print value of i

}

}

Example (3)- using if with OR opetator

If(i>5) //if value of I is greater then 5 then go inside the if statement

{

//if value of i is equal to 6 or i is divisible by 2 then go inside if statement. We use or(||) operator in if statement it means if any one condition is true the this if statement will be execute

If(i==6 || I%2==0)

{

Print the value of i

}

}


Related Solutions

Positive, Negative, or zero. Suppose you are looking at three separate relationships that are modeled by...
Positive, Negative, or zero. Suppose you are looking at three separate relationships that are modeled by linear functions. One linear model has a positive slope, one has a negative slope, and one has a slope of zero. What do these slopes tell you about the relationships they model? Find practical examples of each of the three.
A matlab program to enter N numbers and count the positive, negative and zero numbers. Then...
A matlab program to enter N numbers and count the positive, negative and zero numbers. Then print the results
For the equations below, is the entropy positive, negative, or approximately zero? - How did you...
For the equations below, is the entropy positive, negative, or approximately zero? - How did you determine this? 2Na(s) + Cl2(g) g 2NaCl(s) 2C2H2(g) + 3O2(g) g 4CO(g) + 2H2O(g) C2H4(g) + 3O2(g) g 2CO2(g) + 2H2O(g) SO2(g) + 2H2S(g) g 3S(s) + 2H2O(g) H2(g) + F2(g) g 2HF(g)
Suppose you have a list containing k integer numbers. Each number could be positive, negative, or...
Suppose you have a list containing k integer numbers. Each number could be positive, negative, or zero. Write pseudocode for a program that first asks the user for each of the numbers. After that, it should determine and display the number from the list that is nearest to the positive number five (5). Notes: 1. Try working this out for k = 4 and k = 5. See if you can find an algorithmic pattern that can be extended for...
Write one example of each: Positive conformity: Negative conformity: Positive obedience: Negative obedience:
Write one example of each: Positive conformity: Negative conformity: Positive obedience: Negative obedience:
Give an example of a negative or positive externality that you know about or have experienced....
Give an example of a negative or positive externality that you know about or have experienced. Once you have identified the externality, describe what is causing it and who it is effecting. Once you have done this, discuss the public policy or the private solution that is being applied to the negative or positive externality and discuss if it's working and how the externality is being internalized.
Give an example of what you think is a positive and a negative externally. Draw both...
Give an example of what you think is a positive and a negative externally. Draw both a positive and negative graphs of both and explain briefly the Op and Os and Cost effects with these different MPC and MPS Supply firms.
Provide an example of ‘positive’ “externality” and an example of ‘negative’ “externality.” Explain The effect in...
Provide an example of ‘positive’ “externality” and an example of ‘negative’ “externality.” Explain The effect in terms of “market failure” of each example.
What’s an example of a perfect positive and a perfect negative correlation.
What’s an example of a perfect positive and a perfect negative correlation.
14. Use Descartes’ Rule to determine the possible number of positive, negative, and non-real solutions. Make...
14. Use Descartes’ Rule to determine the possible number of positive, negative, and non-real solutions. Make a table of possible real/complex solutions. (10 points) ?(?)=?^?−??^?−??^?+??−?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT