S
sathyashrayan
Please look at the following code:
static char *text[] = {"th", "st", "nd", "rd"};
char *ordinal_text(int number)
{
if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
number = 0;
return text[number];
}
#include <stdio.h>
int main(void)
{
int i;
for (i = 0; i < 26; ++i)
printf("%d%s\n", i, ordinal_text(i));
return 0;
}
According the code above the out put is as follows:
0th
1st
2nd
3rd
4th
5th
6th
7th
8th
9th
10th
11th
12th
13th
14th
15th
16th
17th
18th
19th
20th
21st
22nd
23rd
24th
25th
Which is exactly what is expected.But don't understand output.How come
the output occurred as expected.
if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
The number should be less than 20 but greater than 9. But how each
element in the iteration of array prints accordingly. Can any one help
me to understand this simple program? Thanks.
--
"combination is the heart of chess"
A.Alekhine
Mail to:
sathyashrayan AT gmail DOT com
static char *text[] = {"th", "st", "nd", "rd"};
char *ordinal_text(int number)
{
if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
number = 0;
return text[number];
}
#include <stdio.h>
int main(void)
{
int i;
for (i = 0; i < 26; ++i)
printf("%d%s\n", i, ordinal_text(i));
return 0;
}
According the code above the out put is as follows:
0th
1st
2nd
3rd
4th
5th
6th
7th
8th
9th
10th
11th
12th
13th
14th
15th
16th
17th
18th
19th
20th
21st
22nd
23rd
24th
25th
Which is exactly what is expected.But don't understand output.How come
the output occurred as expected.
if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
The number should be less than 20 but greater than 9. But how each
element in the iteration of array prints accordingly. Can any one help
me to understand this simple program? Thanks.
--
"combination is the heart of chess"
A.Alekhine
Mail to:
sathyashrayan AT gmail DOT com