the number 138 is called well ordered number because the
three digits in the number (1,3,8) increase from left to right
(1<3<8). the number 365 is not well ordered coz 6 is larger
than 5.
write a program that wull find and display all possible
three digit well ordered numbers.

sample:
123,124,125,126,127,128,129,134
,135,136,137,138,139,145,146,147
148
149,156.......789

Answer Posted / ankit kamboj

#include<stdio.h>
main()
{
int i,j,n,a,n1,cnt=0;;

int arr[3];
for(n=100;n<=999;n++)
{ n1=n;
for(i=2;i>=0,n1>0;i--,n1=n1/10)
{ a=n1%10;
arr[i]=a;
}

for(i=0;i<3;i++)
printf("%d ",arr[i]);

if(arr[0]<arr[1] && arr[1]<arr[2])
{printf("It is well ordered \n"); cnt++;}
else
printf("It is not well order\n");

}
printf("The n0. of well ordered no. are %d\n",cnt);
}

Is This Answer Correct ?    6 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }

689


What is the use of gets and puts?

590


What Is The Difference Between Null And Void Pointer?

630


What is a good data structure to use for storing lines of text?

584


What do you mean by recursion in c?

615






Why is main function so important?

605


What are the loops in c?

589


Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].

634


How we can insert comments in a c program?

619


What is typedf?

662


How do you define a function?

577


What is the value of uninitialized variable in c?

562


What is a wrapper function in c?

573


What is the general form of a C program?

593


Is there a way to jump out of a function or functions?

627