C Programming L-2
C Programming L-2
LECTURE 2 By CSTE 14
DECISION MAKING
(IF, ELSE IF , ELSE)
• An if statement consists of a Boolean expression followed by one or
more statements.
• Syntax:
#include<stdio.h>
int main()
{
int a = 10;
if(a > 20) {
printf(“a is greater than 20\n”);
}
printf(“Value of a is : %d\n”, a);
return 0;
}
DECISION MAKING
(IF, ELSE IF , ELSE)
• An if statement can be followed by an optional else statement, which
executes when the Boolean expression is false.
• Syntax:
#include<stdio.h>
int main()
{
int a = 10;
if(a > 20) {
printf(“a is greater than 20\n”);
}
else {
printf(“a is greater than 20\n”);
}
printf(“Value of a is : %d\n”, a);
return 0;
}
DECISION MAKING
(IF, ELSE IF , ELSE)
• An if statement can be followed by multiple optional else if statements.
DECISION MAKING
(IF, ELSE IF , ELSE)
#include <stdio.h>
int main () {
int x = -20;
if (x == 0) {
printf("Number is zero\n");
}
else if (x < 0) {
printf("Number is negative\n");
}
else {
printf("Number is positive\n");
}
return 0;
}
EXERCISES
1. Write a C program to check whether a number is negative, positive or zero.
2. Write a C program to check whether a number is divisible by 5 and 11 or not.
3. Write a C program to find maximum between three numbers.
4. Write a C program to find maximum between two numbers.
5. Write a C program to check whether a number is even or odd.
6. Write a C program to check whether a character is alphabet or not.
7. Write a C program to input any alphabet and check whether it is vowel or
consonant.
8. Write a C program to input any character and check whether it is alphabet, digit
or special character.
9. Write a C program to check whether a character is uppercase or lowercase
alphabet.
10. Write a C program to input week number and print week day.
ASSESMENT
1. Write a C program to input month number and print number of days in that month.
2. Write a C program to count total number of notes in given amount.
3. Write a C program to input angles of a triangle and check whether triangle is valid or not.
4. Write a C program to input all sides of a triangle and check whether triangle is valid or not.
5. Write a C program to check whether the triangle is equilateral, isosceles or scalene triangle.
6. Write a C program to calculate profit or loss.
7. Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics
and Computer. Calculate percentage and grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
THANKS TO ALL!