Operator which accepts three value : Operator Ternary « Language Basics « C / ANSI-C






Operator which accepts three value


#include <stdio.h>

int main(void)
{
  int isqrd, i;

  printf("Enter a number: ");
  scanf("%d", &i);

  isqrd = i>0 ? i*i : -(i*i);

  printf("%d squared is %d", i, isqrd);

  return 0;
}


  

           
       








Related examples in the same category

1.Ternary (?) operator
2.Use ternary operator in printf
3.Add function to the Ternary operator
4.Ternary operator inside if else
5.Simple Ternary operator
6.Write expression inside Ternary operator