Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Vvghhhj

Rating
-
Sold
-
Pages
27
Uploaded on
11-07-2024
Written in
2023/2024

Lecture notes of 27 pages for the course C programming at Mdu (Vvggg)

Institution
Course

Content preview

UNIT II

Decision Making & Branching

C has decision-making statements to support conditional logic. C conditional
statements allow you to make a decision based upon the result of a condition.
These statements are called Decision Making Statements or Conditional
Statements. C has a number of alternatives to add decision-making in the
code. In programming, we come across situations when we need to make some
decisions. Based on these decisions, we decide what should we do next.
Similar situations arise in algorithms too where we need to make some
decisions and based on these decisions, we will execute the next block of code.

This type of structure requires that the programmers indicate several
conditions for evaluation within a program. The statements will be executed
if the condition becomes true, and optionally, if the condition
becomes false, an alternative statement or set of statements will be executed.

The flowchart of the Decision-making technique in C can be expressed as:




Decision making is about deciding the order of execution of statements based
on certain conditions or repeat a group of statements until certain specified
conditions are met. C language handles decision-making by supporting the
following statements,

• if Statement
• if-else Statement
• Nested if Statement
• if-else-if Ladder
• switch Statement
• Conditional Operator
• Jump Statements:
➢ break

, ➢ continue
➢ goto
➢ return




Decision Making with If Statement:

In C programming, the if statement is a fundamental control structure used
for decision making. It allows you to execute a block of code if a specified
condition evaluates to true.

Syntax:

if (condition)

{

// block of code to be executed if the condition is true;

}

, Flowchart of If Statement:




If the condition is fails the control goes outside the if statement. The if
statement in C allows you to control the flow of your program based on
conditions. For example write a program in C to find if the entered number
is positive or negative:

#include <stdio.h>
void main( )
{
int num;
printf ( “ Enter a number”);
scanf ( “%d”, &num);
if (num > 0)
{
printf("%d is a positive number.\n", num);
}
if (num < 0)
{
printf("%d is a negative number.\n", num);
}
if (num = = 0)
{
printf (“Entered number is Zero”);
}
}
In this example:

Written for

Institution
Course

Document information

Uploaded on
July 11, 2024
Number of pages
27
Written in
2023/2024
Type
Class notes
Professor(s)
Vishakha
Contains
Bca

Subjects

$40.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
vishakhashrivastava

Get to know the seller

Seller avatar
vishakhashrivastava Self
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions