Question

In: Computer Science

Implement if else loop to find out if the given number is positive or negative or...

Implement if else loop to find out if the given number is positive or negative or zero. You would be hardcoding the number in the below example I used 8. But you can use a different number.

Solutions

Expert Solution

ans)

Explained using C program :

The code for above program is :

#include <stdio.h>   --------------- header files used in C ( to call built in function )
void main() {
double num;

printf("Enter the number ");

scanf("%lf", &num); ----------------take  input from user

if (num <= 0.0) {
if (num == 0.0)
printf("you entered zero !");
else
printf("you entered a negative number !! ");
} else
printf("you entered a positive number!");

}

output :

Enter the number -2.34 ------------ displays on screen after RUN

you entered a negative number !!


EXPLANATION OF PROGRAM :

basic terms :

if-else statement in C : if the given condition in if statement evaluates as TRUE then inside the if-block get executed , otherwise the else block get executed.

double : - a data type used in C to accept the decimal valued numbers, the double is having double precision ( 64 bit ) floating-point representation ( more accuracy like :  0.01230393... )

- the variable num is declared using data type double, next the scanf() funtion is called ( to take input from user side ). in the scanf syntax, there must be %lf to accept the double value . after reading value and store it in num, the next statement,if- else get executed, if the num is less than or equal to zero the control goes to inside block and there is another if-else statement to print either zero or negative.

if the first condition is wrong then control will jumb to else part and the statement "entered a positive number get executed .


Related Solutions

Given an array of positive numbers and a positive number S, find the length of the...
Given an array of positive numbers and a positive number S, find the length of the smallest contiguous subarray whose sum is greater than or equal to S. Return 0, if no such subarray exists. Example 1 Input: [2, 1, 5, 2, 3, 2], S=7 Output: 2 Explanation: The smallest subarray with a sum great than or equal to '7' is [5, 2]. Example 2 Input: [2, 1, 5, 2, 8], S=7 Output: 1 Explanation: The smallest subarray with a...
A process is carried out at constant pressure. Given that ∆E is positive and ∆H is negative,
A process is carried out at constant pressure. Given that ∆E is positive and ∆H is negative, D) the system loses heat and contracts during the process Which equation represents the reaction that corresponds to the standard enthalpy of formation b of CHCl3 at 25° (∆Hf of CHCl3)?C) 2 C(s) +H2(g) +3Cl2(g) ---> 2CHCl3(l) The reaction 4 Ag(s) +O2(g) ---->2AgO(s) favors Ag2O at low temperature, but it favors Ag and O2 at high temperatures. How can this be explained in...
Give two examples of a negative feedback loop and one example of a positive feedback loop...
Give two examples of a negative feedback loop and one example of a positive feedback loop within normal physiologic function. Describe each homeostatic mechanism using detailed descriptions. For each example predict the result at an organismal level if normal function was impaired at the molecular level.
Be able to describe the how a positive and negative feedback loop differ in regulating a...
Be able to describe the how a positive and negative feedback loop differ in regulating a body’s function. Then using a specific set of hormones, you learned about (you select which ones…a pair) describe how they work in a negative feedback loop. Include in your description where they are released from, what triggers each one of them to be released, what actions they have and if they have specific target tissues or are generally dispersed throughout the body. Finally, how...
4. Explain the difference between a positive and negative hormonal feedback loop. How is the testis...
4. Explain the difference between a positive and negative hormonal feedback loop. How is the testis (i.e. testosterone) regulated ? Explain why giving exogenous testosterone has little effect on serum levels but dramatic lowering of testicular testosterone concentrations. (10 points)
Given an array of positive integers except one negative integer. Develop a divide-conquer algorithm to find...
Given an array of positive integers except one negative integer. Develop a divide-conquer algorithm to find the index of the negative integer, and compute its average complexity.
Input 100 numbers and find and output how many numbers are positive and negative, find and...
Input 100 numbers and find and output how many numbers are positive and negative, find and output average of these numbers Write using vb.net
Label AND Describe a feedback loop for: ONE negative feedback ONE positive feedback ONE antagonistic pair...
Label AND Describe a feedback loop for: ONE negative feedback ONE positive feedback ONE antagonistic pair of feedbacks Include all 5 steps for each feedback
Go to the internet and find a news article that discusses a potential positive or negative...
Go to the internet and find a news article that discusses a potential positive or negative externality. Summarize key points in your initial discussion post. Be sure to use the concepts and frameworks we are covering this week. For example, you may want to address what externality this regulation attempting to address? Is it a positive or negative externality? What is the current policy being used? Is there an alternative policy approach that may work better/worse (taxes or subsidies, for...
Write a loop that reads positive integers from standard input, printing out those values that are...
Write a loop that reads positive integers from standard input, printing out those values that are greater than 100, and that terminates when it reads an integerthat is not positive. The values should be separated by single blank spaces. Declare any variables that are needed. PLEASE ANSWER IN C
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT