Professional Documents
Culture Documents
Practical 03
Practical 03
If conditions:
Syntax 01:
if(condition) {
//Code
}
Syntax 02:
if(condition) {
//Code
} else
{
//Code
}
Syntax 03:
if(condition) {
//Code
}
else if(condition)
{
//Code
} else
{
//Code
}
Relational Operators
Relational Operators are used in decision making and loops in C programming.
Operator Meaning
== Equal to
> Greater than
< Less than
!= Not equal to
>= Greater than or equal to
<= Less than or equal to
Logical Operators
Logical operators are used to combine expressions containing relation operators.
In C there are 3 logical operators.
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT
Activities:
2. Write a program to show the grade of a student for the input marks. (The
program inputs the marks and show the grade)
Marks Grade
Greater than 75 (including 75) A
Greater than 55 (including 55) B
Greater than 40 (including 40) C
Below 40 (not including 40) D
3. Write a program that reads the user’s age and prints: * “You are a child”,
if age is less than 18.
* “You are an adult”, if is between 18 and 65(including 18 & 65).
* “You are a senior citizen”, if age is greater than 65.
5. Write and run a program that simulates a simple calculator. It reads two
integers and a character (Try the same program in two different approaches).
* If the character is +, the sum is printed;
* If the character is -, the difference is printed;
* If the character is *, the product is printed;
* If the character is /, the quotient is printed and
* If the character is %, the remainder is printed
9. Write a program to read a single character from the terminal and classify it
as an alphabetic character (a-z or A-Z), a digit (0-9) or a special character
(anything else).