Basic Programming Lab C Conditional Expression Conditional Expression

Basic Programming Lab C@ Conditional Expression

Conditional Expression. The ternary operator is an operator that takes three arguments. The first argument is a comparison argument, the second is the result upon a true comparison, and the third is the result upon a false comparison. ternary operator (condition) ? X : Y If Condition is true ? then value X : otherwise value Y exp 1 ? exp 2 : exp 3

Example: a=10; b=20 big = a > b ? a : b;

ASCII American Standard Code for Information Interchange, is a character encoding standard for electronic communication. /* C Program to find ASCII Value of a Character */ #include <stdio. h> int main() { char ch; printf("n Please Enter any character n"); scanf("%c", &ch); printf("n The ASCII value of given character = %d", ch); return 0; }

Assignments: 1. 2. 3. 4. 5. 6. C program to check whether a number is positive, negative or zero Write a program to find biggest of 3 numbers using ternary operator. C program to check whether a character is alphabet or not C program to check vowel or consonant C program to enter week number and print day of week C++ program to check whether the given number is EVEN or ODD by using ternary operator. 7. Write a program to check given number is even or odd and also find its sign such as positive or negative using conditional statements such as if and switch.
- Slides: 5