C examples for Operator:Conditional Operator
However, this program preserves the sign (10 squared is 100 and -10 squared is -100).
#include <stdio.h> int main(void) { int isqrd, i;//from ww w . j av a2s . c om printf("Enter a number: "); scanf("%d", &i); isqrd = i>0 ? i*i : -(i*i); printf("%d squared is %d", i, isqrd); return 0; }