prev | Logical Opearators 18. Single digit or not (Logical AND) (28.6.2009) /* Program# 18 date : 25-12-2008 Single digit or not */ #include <stdio.h> main(){ int n; printf("\nEnter a positive number :"); scanf("%d",&n); if(n>=0 && n<=9) printf("Single digit number");// this will be printed, only if both the conditions are true. else printf("Not a Single digit number"); } output: Enter a positive number : 5 Single digit number Things to note: Hierarchy of operators:
Since the relational operator has higher precedence over Logical AND, it is evaluated first and the result is combined with && to give the result. |
next |