Basic 256 program write a program to accept a number and check whether its positive and negitive
Answers
Answer:
Explanation:
Logic to check positive, negative or zero
Logic of this program is simple if you know basic maths. Let us have a quick look about number properties.
A number is said negative if it is less than 0 i.e. num < 0.
A number is said positive if it is greater than 0 i.e. num > 0.
We will use the above logic inside if to check number for negative, positive or zero. Step by step descriptive logic to check negative, positive or zero.
Input a number from user in some variable say num.
Check if(num < 0), then number is negative.
Check if(num > 0), then number is positive.
Check if(num == 0), then number is zero.
Programme ----
/**
* C program to check positive negative or zero using simple if statement
*/
#include <stdio.h>
int main()
{
int num;
/* Input number from user */
printf("Enter any number: ");
scanf("%d", &num);
if(num > 0)
{
printf("Number is POSITIVE");
}
if(num < 0)
{
printf("Number is NEGATIVE");
}
if(num == 0)
{
printf("Number is ZERO");
}
return 0;
}
Language:
BASIC-256
Program:
input "Enter a number: ", a
if a>=0 then
print "It's positive"
else
print "It's negative"
endif
Output:
Enter a number: 12
It's positive
Explanation:
- Line 1: takes input in a.
- Lines later: check condition for if the number is positive or not.