You are on page 1of 4

12/19/2022

Lecture-13
Corse Title: Programming Language
Course Code: EL-255
Course Teachers: Dr. Sadia Muniza Faraz
Semester: Fall-2022
Offered to: S.E. (Electronic Engineering)

Department of Electronic Engineering


NED University of Engineering and Technology Karachi, Pakistan

Chapter-4

Conditions

1
12/19/2022

If-else
"else" statement is executed when the if statement is FALSE.

if (expression)
{
statement1;
statement2;
.
.
}
else
{
statement_A;
statement_B;
.
}
3

If, else and else if Statements


Nested if -else
#include <stdio.h>
If a program has to
main()
make a series of
{
decisions. Then
int i;
nested if statements
for (i=-5; i<=5; i++)
are used.
{
if (i > 0)
program print if (i%2 == 0)
printf("%d is an even number.\n", i);
even, odd, zero else
and negative printf("%d is an odd number.\n", i);
else if (i == 0)
numbers printf("The number is zero.\n");
else
printf("Negative number: %d\n", i);
}
} 4

2
12/19/2022

Program: take some text as input and


count number of vowels in it
// #include all required header files

void main (void)


{
char ch;
int count=0;
printf(“ vowels counter in text”);
printf(“ \n write a statement or paragraph and press enter key in the end”)
do
{
ch=getche(); // getche() will show the typed character on scree
if(ch==‘a’ ||ch==‘e’||c==‘i’||ch==‘o’ ||ch==‘u’)
count++;
}
while (ch!=‘\r’);
printf(\n\n total number of vowels i the text are = %d”, count);
getch();
}
5

Home Work

Write a program which takes some text as input and


count total number of vowels and consonants in the text

Write a program which takes some text as input and


counts each vowel separately and prints their count.

3
12/19/2022

Conditional Statement
max=(num1 > num2) ? num1:num2;

THE END

You might also like