What is the difference a constant and variable? Also write a Basic language program to input any number, if number is greater than zero, then
display "positive number otherwise display "Negative number".
Answers
In the following program we are checking whether the input integer number is positive or negative. If the input number is greater than zero then its positive else it is a negative number. If the number is zero then it is neither positive nor negative. Same logic we have followed in the below C program.
/* Description: A program to check whether the input
* integer number is positive or negative.
* Written by: Chaitanya Singh
* Published on: beginnersbook.com
*/
#include <stdio.h>
void main()
{
int num;
printf("Enter a number: \n");
scanf("%d", &num);
if (num > 0)
printf("%d is a positive number \n", num);
else if (num < 0)
printf("%d is a negative number \n", num);
else
printf("0 is neither positive nor negative");
}
Output 1:
Enter a number:
0
0 is neither positive nor negative
Output 2:
Enter a number:
-3
-3 is a negative number
Output 3:
Answer: