Friday, October 1, 2010

Simple nested if program in c language

Code a C program to classify the given inputted number is single, two, three and
four digit using nested if … else statements.

int main()
{
int n;
printf("Enter a number with less than or equal to 4 digits: ");
scanf("%d",&n);
int x=0;
if(n/10000==0)
{
x=4;
if(n/1000==0)
{
x=3;
if(n/100==0)
{
x=2;
if(n/10==0)
{
x=1;
}
}
}
}
printf("It is a %d digit number",x);
getch();
}

No comments:

Post a Comment