Well Ordered Numbers The number 138 is called well-ordered because the digits in the number (1,3,8) increase from left to right (1 < 3 < 8). The number 365 is not well-ordered because 6 is larger than 5. Write a program that will find and display all possible three digit well-ordered numbers. Report the total number of three digit well-ordered numbers.
Ans :
void main() {
int i, j, k, total = 0;
for(i = 1; i<8; i++) {
for(j = i+1; j<9; j++) {
for(k = j+1; k<10; k++) {
printf("%d%d%d ",i,j,k);
total++;
if(total % 8 == 0) printf("\n");
}
}
}
printf("\n");
printf("Total Well Ordered Numbers of 3 digits are: %d\n",total);
getch();
}
Ans :
void main() {
int i, j, k, total = 0;
for(i = 1; i<8; i++) {
for(j = i+1; j<9; j++) {
for(k = j+1; k<10; k++) {
printf("%d%d%d ",i,j,k);
total++;
if(total % 8 == 0) printf("\n");
}
}
}
printf("\n");
printf("Total Well Ordered Numbers of 3 digits are: %d\n",total);
getch();
}
0 comments:
Post a Comment