Tuesday, 16 September 2014

Write a C program " if statement"

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


#include <stdio.h>
      int main(){
      int num;
      printf("Enter a number to check.\n");
      scanf("%d",&num);
      if(num<0) {      /* checking whether number is less than 0 or not. */ 
            printf("Number = %d\n",num); 
      }  
/*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;
}




No comments:

Post a Comment