#include <unistd.h>
void triplet(void);
int main(void)
{
triplet();
}
void triplet(void)
{
char i, j, k;
i = '0';
j = '1';
k = '2';
while (i < j)
{
j = i + 1;
k = j + 1;
while (j < k)
{
k = j + 1;
while (k <= '9')
{
write(1, &i, 1);
write(1, &j, 1);
write(1, &k, 1);
if ( ( i != '7' ) && ( j != '8' ) && ( k != '9' ) )
{
write(1, ", ", 2);
}
k++;
}
j++;
}
i++;
}
}
The goal of the if
statement is to control when to print the comma-space separator (", "
) between the digit combinations. I want to print the separator after every combination except the last one (“789”).
The following conditional statement does not work as intended:
if ( ( i != '7' ) && ( j != '8' ) && ( k != '9' ) )
This one does:
if ( !( i == '7' && j == '8' && k == '9' ) )
What is wrong with the first conditional?
1