Write a C program to print the number entered by user only if the number entered is negative.


#include<stdio.h>
int main(){
int n;
printf(“Enter a number to check.\n”);
scanf(“%d”,&n);
if(n<0)
{ /* checking whether number is less than 0 or not. */
printf(“Number = %d\n”,n);
}
/*If test condition is true, statement above will be executed, otherwise it will not be executed */
printf(“The if statement in C programming is easy.”);
return 0;
}

output 1:
Enter a number to check.
-1
Number = -1
The if statement in C programming is easy.

output 2:

Enter a number to check.
3

Leave a comment

Your email address will not be published. Required fields are marked *