Find Positive or Negative Number in C.

In this article we learn how to find positive or Negative number in C .

Let’s write program to find positive or negative nmber in C .

Step 1: Let’s open turbo c/c++ and write the following code

//Code

//Add preprocessor file

#include<stdio.h>

#include<conio.h>

void main()

{

//Declare variable

long int n;

//Clear screen

clrscr();

printf(“enter any number :”);

// Assign value in variable

scanf(“%li”,&n);

if(n>0)

printf(“number is positive”);

else if(n<0)

printf(“number is negative”);

getch();

}

 

positive.cpp

 

Step 2: Now save it by pressing F2 and name it POSITIVE.CPP and click OK.

0

 

Step 3: Now compile it by pressing ALT+F9 or click on compile then click on OK.

1

 

Step 4: Run the program by presing ALT+R ,and see the output.

// Output

Suppose if we enter 10

then the result is – nunber is positive.

4

Thank you.

Tags: