Hi,
Yesterday I came across a problem. The problem was to print no.(s); firstly in increasing order then decreasing order. It is not a problem at all. But the real trick was, to print it using a single line of code. I took it as challenge, and designed this code. After getting the desired output, I realized that now I’ve better understanding of ternary operators.
If anyone has some better code, then please share.
Thank you Emblogic.
#include<stdio.h>
int main()
{
int i=-1,j=0,c = 0,n;
printf(“Enter the no.: “);
scanf(“%d”,&n);
while((j<=2*n+1)&&printf(“%d, “, c==0 ? ( i==n ? printf(“\n”), c=i–: ++i) : i– , j++));
return 0;
}