C Program : Check a given integer is positive or negative

 #include <stdio.h>

int main() { int num; printf("Enter an integer: "); scanf("%d", &num); if (num > 0) { printf("%d is a positive integer.\n", num); } else if (num < 0) { printf("%d is a negative integer.\n", num); } else { printf("The number is zero.\n"); } return 0; }



In this program:

  1. We include the standard input/output header file stdio.h.
  2. We declare an integer variable num to store the input integer.
  3. We prompt the user to enter an integer using printf and read the input using scanf.
  4. We use an if-else statement to check if the value of num is positive, negative, or zero.
  5. If num is greater than 0, it is considered a positive integer, and we print a message accordingly.
  6. If num is less than 0, it is considered a negative integer, and we print a message accordingly.
  7. If num is neither positive nor negative (i.e., it's equal to 0), we print a message indicating that it's zero.
  8. The program returns 0 to indicate successful execution.

Compile and run this program, and it will determine whether the input integer is positive, negative, or zero.

Comments

Popular posts from this blog

Video Formats

Where video editing is used

File saving and folder management