0% found this document useful (0 votes)
4 views

UNIT-2 Material - Introduction to Programming (1)

Uploaded by

dasarimurali780
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

UNIT-2 Material - Introduction to Programming (1)

Uploaded by

dasarimurali780
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 57

INTRODUCTION TO PROGRAMMING

UNIT-2: CONTROL STRUCTURES


TABLE OF CONTENTS
S.No Topic Page No
2.1 Sequential Execution 2
2.2 Control Statements 2
2.2.1 if condition 3
2.2.2 if else condition 5
2.2.3 Nested if else statement 13
2.2.4 if else-if ladder statement 14
2.2.5 switch statement 20
2.2.6 while loop 28
2.2.7 do..while loop 40
2.2.8 for loop 42
2.2.9 break statement 52
2.2.10 continue statement 54
2.2.11 goto statement 56

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 1


UNIT-2: CONTROL STRUCTURES
Syllabus: Simple sequential programs, Conditional Statements (if, if-else, switch), Loops (for,
while, do- while) Break and Continue.

2.1 Sequential Execution


• We already know that a program in the C language contains several statements.
• When the program runs, the statements are executed by a compiler.
• The sequence of execution of statements by a compiler is called ‘execution flow’.
• This execution flow is of two types: sequential execution and random execution.
• Executing the statements one by one in a sequential manner is called ‘sequential
execution’.
• This type of execution is suitable for writing simple C programs.
• Executing the statements randomly and repeatedly is called ‘random execution’.
• Executing statements in a random manner helps create better and complex programs.
Random execution is done by using ‘control statements’.
2.2 Control Statements
• Control statements that change the flow of execution in such a way that the programmer
can execute the statements as he/she likes.
• In other words, control statements provide better control to the programmer on the execution
flow of the program.
• The following are the control statements available in C:
• if condition
if…else statement
Nested if-else statement
if else-if ladder statement
switch statement
do…while loop
while loop
for loop
break statement
continue statement
goto statement
return statement
• You must have noticed that in the control statements, sometimes we are using the word
‘statement’ and sometimes ‘loop’.
• In the case of a statement, the given code executes only once; whereas, the code given in
a loop continues to execute repeatedly under the given conditions.
• For example, if… else is a statement and while is a loop.

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 2


2.2.1 if condition
• The if statement is used to check some given condition and perform some operations
depending upon the correctness of that condition.
• It is mostly used in the scenario where we need to perform the different operations for
the different conditions.
• The syntax of the if statement is given below.

if (condition)
{
//statements;
}

• Flow chart for if condition

Example programs on if condition


Program 1 source code: To check whether the given number is even or not

Program 1 output: case-1

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 3


Program 1 output: case-2

Note: In the above case-2 output, the given number is 251 which is odd number. According
the source code, if the given number is even number then statements inside in its block get
executed, otherwise no output. If we want to perform two operations on single condition, then
we have to take help from if-else statement.
Program 2 source code: To find the largest number among three numbers

Program 2 output: case-1

Program 2 output: case-2

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 4


Program 2 output: case-3

Program 2 output: case-4

2.2.2 if else condition


• The if-else statement is used to perform two operations for a single condition.
• The if-else statement is an extension to the if statement using which, we can perform two
different operations, i.e., one is for the True of that condition, and the other is for the False
of the condition.
• Here, we must notice that if and else block cannot be executed simultaneously.
• The syntax of the if-else statement is given below.

if(condition)
{
//statements1;
}
else
{
//statements2;
}
• In the preceding syntax, if the given condition is true, then statements1 will be executed.
If the condition is false, then statements2 will be executed.

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 5


• Flow chart for if else condition

Example programs on if else condition


Program 3:
AIM: Write a C program to find the given number is even or odd
Source code:

Program 3 Output: Case-1

Program 3 Output: Case-2

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 6


Program 4:
AIM: Write a C program to check whether a person is eligible to vote or not
Source code:

Program 4 Output: Case-1

Program 4 Output: Case-2

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 7


Program 5:
AIM: While purchasing certain items, a discount of 10% of offered if the quantity is more than
1000. If quantity and price per item are input through the keyboard, write a C program to
calculate the total expenses
Source code:

Program 5 Output: Case-1

Program 5 Output: Case-2

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 8


Note: In case of a single statement, curly braces are not mandatory. It is possible to write
if statement in different ways. Observe the following:

Program 6
AIM: Write a C program to check whether a person is eligible to vote or not without curly
braces
source code: without curly braces

Program 6 output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 9


Program 7:
AIM: Write a C program to find whether a given year is leap or not.
Discussion:
1. We know that a year is leap if it is divisible by 4. For example, year 2012 is leap since it
is divisible by 4.
2. For the year representing the beginning of a century like 1900, 2000, 2100, 2200, etc. if it
is divisible by 400, then it is called a leap year.
3. Here, 1900 is not a leap year but 2000 is a leap year because it is divisible by 400.
4. To decide whether a year is a century year or not, divide it by 100. If the year% 100 == 0,
then it is a century year (ex: 2000).
5. If the year% 100 != 0, then it is not a century year (ex: 2012).
6. If the year is not a century year, it should be divisible by 4, else the year should be divisible
by 400.
7. The same logic can be represented in C, as:
if (year%4 == 0 && year%100!=0 || year%400 == 0)
Source code:

Program 7 Output: case-1

Program 7 Output: case-2

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 10


Program 8:
AIM: Write a C program to find the roots of a quadratic equation. The quadratic equation is
ax2+bx+c=0. Given a, b, c values, we should find the value of x. Here, x will have two values,
called ‘roots’ named as ‘x1’ and ‘x2’. To find the nature of the roots, we should first calculate
the ‘discriminator’ (d). The equation of ‘d’ is d=b2-4*a*c.
Source code:

Program 8 Output: Case-1

Program 8 Output: Case-2

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 11


Program 9:
AIM: In a company, if the employee salary is less than Rs.1500, then HRA=10% of basic
salary and DA=90% of basic salary. If his salary is either equal or above Rs.1500 then
HRA=Rs.500 and DA=98% of basic salary. If the employee’s salary is input through the
keyboard write a C program to find gross salary.
Source code:

Output: case-1

Output: case-2

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 12


2.2.3 Nested if else statement
• A nested if-else statement is an if statement inside another if statement. The general syntax
of nested if-else statement in C is as follows:
• Syntax:
if (condition1)
{
/* code to be executed if condition1 is true */
if (condition2)
{
/* code to be executed if condition2 is true */
}
else
{
/* code to be executed if condition2 is false */
}
}
else
{
/* code to be executed if condition1 is false */
}
• As you can see, the outer if statement has two possible paths: one for when the condition is
true, and another for when the condition is false.
• If the condition is true, the program will execute the code inside the block associated with
the outer if statement.
• However, if the condition is false, the program will skip over that block and move to the
else block.
• Within the outer if block, there is another if statement, which can also have two possible
paths depending on whether the condition is true or false.
Program 10: AIM: Write a C program to find the given number is positive or negative or
neutral using nested if-else
Source code:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 13


Program 10 Output: Case-1

Program 10 Output: Case-2

Program 10 Output: Case-3

2.2.4 if else-if ladder statement


• The if-else-if ladder statement is an extension to the if-else statement.
• It is used in the scenario where there are multiple cases to be performed for different
conditions.
• In if-else-if ladder statement, if a condition is true then the statements defined in the if block
will be executed, otherwise if some other condition is true then the statements defined in the
else-if block will be executed, at the last if none of the condition is true then the statements
defined in the else block will be executed.
• Syntax:
if(condition1){
//code to be executed if condition1 is true
}else if(condition2)
{
//code to be executed if condition2 is true
}
else if(condition3)
{
//code to be executed if condition3 is true
}
...................
else{
//code to be executed if all the conditions are false }

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 14


• Flow chart of else-if ladder statement

Program 11:
AIM: Write a C program on else if-ladder statement
Source code:

Program 11 Output: Case-1

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 15


Program 11 Output: Case-2

Program 11 Output: Case-3

Program 11 Output: Case-4

Program 12:
AIM: The marks obtained by a student in 5 different subjects are input through the keyboard.
The student gets a division as per the following rules:
Rule 1: Percentage above or equal to 60 – First division
Rule 2: Percentage between 50 and 59 – Second division
Rule 3: Percentage between 40 and 49 – Third division
Rule 4: Percentage less than 40 – Fail
Source code:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 16


Program 12 Output: Case-1

Program 12 Output: Case-2

Program 13:
AIM: Write a program to calculate the salary as per the following table:
Gender Year of service Qualifications Salary
>=10 Post Graduate 11,000
>=10 Graduate 10,000
Male
<10 Post Graduate 9,000
<10 Graduate 7,000
>=10 Post Graduate 12,000
>=10 Graduate 9,000
Female
<10 Post Graduate 10,000
<10 Graduate 6,000

Program 13 Source code:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 17


Program 13 Output: Case-1

Program 13 Output: Case-2

Program 14:
AIM: Write a C program to find ASCII value for various character like lower case alphabet,
upper case alphabet, digit (0-9) and special symbol
Source code:

Program 14 Output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 18


Program 15:
AIM: Write a C program to determine whether the character is a capital letter, small letter,
digit or a special symbol. The following table shows the range of ASCII values for various
characters.
Characters ASCII Range Values
A-Z 65-90
a-z 97-122
0-9 48-57
Special symbols 0-47, 58-64, 91-96, 123-127
Source code:

Program 15 Output: case-1

Program 15 Output: case-2

Program 15 Output: case-3

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 19


Program 15 Output: case-4

2.2.5 switch statement


• The switch statement in C is an alternate to if-else-if ladder statement.
• The switch statement is useful to execute a particular task from among several tasks
depending on the value of a variable or expression.
• Syntax:
switch(variable or expression)
{
case value1: statements1; //code to be executed;
break; //To stop case value1
case value2: statements2; //code to be executed;
break; : //To stop case value2
case valuen: statementsn; //code to be executed;
break; //To stop case valuen
default: default_statements; //code to be executed if all cases are not matched;
}

Rules for switch statement:


1) The switch expression must be of an integer or character type.
2) The case value must be an integer or character constant.
3) The case value can be used only inside the switch statement.
4) The break statement in switch case is not must. It is optional. If there is no break
statement found in the case, all the cases will be executed present after the matched
case.

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 20


Flow chart of switch case:

Program 16:
AIM: Write a C program to implement switch case statements to perform arithmetic operations
Source code:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 21


Program 16 Output: Case-1

Program 16 Output: Case-2

Program 16 Output: Case-3

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 22


Program 17:
AIM: Write a C program to perform switch case on a character
Source code:

Program 17 Output: case-1

Program 17 Output: case-2

Program 17 Output: case-3

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 23


Program 18:
AIM: Write a C program to perform switch case on a character without break statement
Source code:

Program 18 Output: case-1

Program 18 Output: case-2

Program 18 Output: case-3

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 24


Program 19:
AIM: Write a C program to implement switch case on expression value
Source code:

Program 19 Output: case-1

Program 19 Output: case-2

Program 19 Output: case-3

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 25


Program 20:
AIM: Write a C program to implement switch case on relational operators
Source code:

Program 20 Output: case-1

Program 20 Output: case-2

Program 20 Output: case-3

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 26


Program 21:
AIM: Write a C program to implement nested switch case
Source code:

Program 21 Output:

Note: Change the a and b values and try to execute the above program in your PC/Laptop, to
find the remaining cases of output.
Note: However, the usage of switch with conditions isn't ideal and doesn't work as intended in
C. Observe the below program: Error program. So, the solution is converting the below code
by using if-else.

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 27


LOOPS
• The looping can be defined as repeating the same process multiple times until a specific
condition satisfies.
• The looping simplifies the complex problems into the easy ones.
• It enables us to alter the flow of the program so that instead of writing the same code again
and again, we can repeat the same code for a finite number of times.
• For example, if we need to print the first 10 natural numbers then, instead of using the
printf() statement 10 times, we can print inside a loop which runs up to 10 iterations.
Advantages of loops in C
1) It provides code reusability.
2) Using loops, we do not need to write the same code again and again.
• There are three types of loops in C. They are:
1. while
2. do while
3. for
2.2.6 while loop
• In a while loop, loop, the condition is tested first and then only the statements are executed.
• The while loop executes a group of statements repeatedly as long as a condition is true.
• Syntax:
while(condition)
{
//statements;
}
• The compiler tests the condition first. If the condition is true, then the statements in the
while loop are executed. The compiler goes back and tests the condition again. If the
condition is true, then the statements will be executed again. In this way, as long as the
condition remains true, the statements are repeatedly executed.
Flowchart of while loop:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 28


Program 22:
AIM: Write a C program to implement while loop to print 1 to 10 numbers without halting
(Infinite loop)
Source code:

Program 22 Output: (Infinite loop)

Program 23: A C program to implement while loop to print 1 to 10 natural numbers


Source code:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 29


Program 23 Output:

Program 24: A C program to implement while loop to print 10 to 1 natural numbers


Source code:

Program 24 Output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 30


Program 25:
AIM: Write a program to calculate overtime pay of 10 employees. Overtime is paid at the rate
of Rs. 120.00 per hour for every hour worked above 40 hours. Assume that employees do not
work for fractional part of an hour.
Source code:

Output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 31


Program 26:
AIM: Write a program to find the factorial value of any number entered through the keyboard.
Source code:

Output:

Program 27:
AIM: Write a program to find the value of one number raised to the power of another number
Source code:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 32


Program 27 Output: case-1

Program 27 Output: case-2

Program 28:
AIM: Write a program to find the reverse of a given number using while loop
Source code:

Output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 33


Program 29:
AIM: Write a program to find the sum of digits of a number using while loop
Source code:

Output: case-1

Output: case-2

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 34


Program 29:
AIM: Write a C program to find the Fibonacci sequence using while loop
Source code:

Output: case-1

Output: case-2

Output: case-3

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 35


Program 30:
AIM: Write a C program to demonstrate nested while loop
Source code:

Output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 36


Program 31:
AIM: Write a C program to find the given number is prime number or not
Source code:

Output: Case-1

Output: Case-2

Output: Case-3

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 37


Program 32:
AIM: Write a C program to find a given number is palindrome or not
Source code:

Output: case-1

Output: case-2

Output: case-3

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 38


Program 33:
AIM: Write a C program to check whether the given number is Armstrong number or not
Source code:

Output: case-1

Output: case-2

Output: case-3

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 39


2.2.7 do..while loop
• The do…while loop is useful to execute a group of statements repeatedly as long as a
condition is true.
• Once the condition becomes false, the loop terminates.
• Syntax:
do
{
statements;
}while(condition);
• First of all, the compiler executes the statements and then tests the condition.
• If the condition is true, it goes back and executes the statements the second time.
• If the condition is true again, it goes back and executes the statements.
• In this way, the statements are executed repeatedly as long as the condition is true.
• Once the condition becomes false, the loop terminates.
Program 34:
AIM: Write a C program to demonstrate do..while loop
Source code:

Output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 40


Program 35:
AIM: Write a C program to demonstrate multiplication table do..while loop
Source code:

Output: case-1

Output: case-2

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 41


2.2.8 for loop
• The for loop is useful to execute a group of statements as long as a condition is true.
• This loop is more compact and complex than the do…while or while loops.
• The for loop is more suitable when the programmer knows how many times exactly the
statements should be executed.
• It means that the for loop is suitable to execute statements a fixed number of times.
• Syntax 1:
for(expresson1; expression2; expression3)
{
statements;
}
• Syntax 2:
for (initializationStatement; conditionTest; updateStatement)
{
//Statements to be executed
}
• Example:
for (i=1;i<=10;i++)
{
printf(“%d”,i);
}
• Here, expression1 is called ‘initialization expression’ as it is used to initialize a variable
(i= 1).
• Expression1 is executed only once at the beginning of the loop.
• Expression2 is called ‘conditional expression’ as it represents a condition (i<=10).
• As long as this condition is true, the statements inside the for loop will be executed.
• Expressoin3 is called ‘modifying expression’ as it either increments or decrements the
value of the variable (i++).
• The for loop in the example prints numbers from 1 to 10 since the starting value of ‘i’ is 1,
the ending is 10 and each time the value of ‘i’ is incremented by 1.
• So, the values of ‘i’ will change as 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
• When ‘i’ value becomes 11, the condition i<=10 becomes false, so the for loop terminates
and ‘i’ value 11 is not displayed.
Program 36:
AIM: Write a C program to display numbers from 1 to 10 using a for loop
Source code:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 42


Program 36 Output:

• It is possible to write a for loop without using any one expression, any two expressions,
or all the three expressions.
Case 1: for loop without initialization statement

Case 2: for loop without initialization and update statements

Case 3: for loop without all the three expressions

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 43


Note:
• In this case -3, expression2 which represents a condition is not present.
• We know that a loop is executed as long as the condition is true.
• Once the condition is false, the loop terminates. Since there is no condition, the for loop
does not know where to stop.
• So, it will continue to execute forever. Such a loop is called an ‘infinite loop’.
Case 4: Infinite for loop terminated after 10th repetition

Output:

Infinite Loops:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 44


Note:
• Using infinite loops is not a good programming habit since the program gets executed
repeatedly and the control does not remain in the hands of the user.
• If a programmer uses an infinite loop in his program, then it is his duty to see that the loop
terminates after some repetitions.
Program 37:
AIM: Write a C program to demonstrate multiplication table using for loop
Source code:

Output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 45


Program 38:
AIM: Write a C program to demonstrate Fibonacci sequence using for loop
Source code:

Program 38 Output: case-1

Program 38 Output: case-2

Program 38 Output: case-3

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 46


Program 38 Output: case-4

Program 39:
AIM: Write a C program to demonstrate Nested for-loop
Source code:

Output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 47


Program 40:
AIM: Write a C program to construct pyramid of numbers
Pattern-1: Half pyramid with *
Source code:

Pattern-1 Output:

Pattern-2: Half pyramid with numbers


Source code:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 48


Pattern-2 Output:

Pattern-3: Inverted pyramid with *


Source code:

Pattern-3 Output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 49


Pattern-4: Inverted pyramid with numbers
Source code:

Pattern-4 Output:

Pattern-5: Full pyramid with *


Source code:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 50


Pattern-5 Output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 51


2.2.9 break statement
• The break statement is used in two ways:
➢ To come out of a loop.
➢ To come out of a switch block.
Program 41:
AIM: Write a C program to terminate while loop using break statement
Source code:

Output:

Note:
What is the difference between exit(0) and exit(1)?
Ans. Both the exit(0) and exit(1) functions will terminate the program. exit(0) represents
normal termination of the program. exit(1) represents that the program is being terminated
because of an error.

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 52


Program 42:
AIM: Write a C program to demonstrate exit(0) for finding the division obtained by a student
depending on his percentage of marks
Source code:

Output: case-1

Output: case-2

Output: case-3

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 53


2.2.10 continue statement
• The continue is statement is useful to continue with the next repetition of a loop.
• When the continue statement is executed inside a loop, the flow of execution goes back to
the starting of the loop and the next repetition takes place.
Program 43:
AIM: Write a C program to demonstrate continue statement using for loop
Source code:

Output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 54


Program 44:
AIM: Write a C program to demonstrate continue statement using for loop (case-2)
Source code:

Output:

What is the difference between the break and continue statements?


Ans. On being executed, the break statement immediately jumps to the end of the current block
of code. The continue statement, however, skips the rest of the code in the current loop and
returns to the beginning of the loop.

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 55


2.2.11 goto statement
• The goto statement is used to directly jump to a particular statement in a program.
• For example, you can use the goto statement if during the execution of the program, you
want to directly jump from statement number 1 to statement number 10.
Syntax:
goto LABEL:
Here, LABEL represents a string constant that points to a statement where the compiler should
jump.
Program 45:
AIM: Write a C program to test whether a given character is upper case letter or lower case
letter
Source code:

Output:

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 56


Program 46:
AIM: Write a C program to demonstrate goto statement
Source code:

Output: case-1

Output: case-2

Prepared by Dr. Vamsi Bandi, Asst. Prof, Dept. of AI, MITS 57

You might also like