Home
User Guide
DB Recovery
Download
Documents
FAQ
Books
About Me
C Programs
Stats

/* 
   Program# 19
   date : 25-12-2008
   Single,two,three or four digit number
*/

#include <stdio.h>
main(){
int n;
printf("\nEnter a positive number :");
scanf("%d",&n);
if(n>=0 && n<=9)  
printf("Single digit number");
else if(n>=10 && n<=99)
printf("\n %d: Two digit number",n);
else if(n>=100 && n<=999)
printf("\n %d: Three digit number",n);
else if(n>=1000 && n<=9999)
printf("\n %d: Four digit number",n);
else
printf("\n %d: Greater than four digits",n);
} 
output:
Enter a positive number : 123
123: Three digit number


Things to note:    else if ladder
The last else will execute only if all the conditions are false.The below given both the forms of if are equal
                                 
                                       
if(condition)                            if(condition)
   do this;                                 do this;
else                                     else if(condition)
{                                            do this;
   if(condition)                       
   do this;
}

Powered by
Open Source Programmers