SlideShare a Scribd company logo
1 of 33
Program 4-1.1
• #include<stdio.h>
• #include<conio.h>
• #include<iostream>
• int main(){
• printf(“hello world!”);
• getch();
• return 0;
• }
Reserved words
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
Data Type Specifiers for printf()
SPECIFIER DATA
TYPES
SAMPLE OUTPUT
c char “%c”, ‘A’ A
d int “%d”, 123 123
i int “%i”, 345 345
f float or
double
“%f”,
123.45
123.45000
0
g float or
double
“%g”,
123.98
123.45
Size Modifiers
Statement Output
“%4i”, 123 *123
“%04i”, 123 0123
“%8.2f”, 12.345 ***12.34
“%.2f”, 1234.567 1234.56
“%1.2f”, 1234.23 1234.23
“%5.1”, 12.3678 12.4
scanf
• scanf(“control_string”, *ampersand+*variable+);
or
• scanf(“%f”, &x);
Program 4-1.2:
• #include<stdio.h>
• void main(){
• int i;
• long l;
• float f;
• double d;
• printf(“Enter a values for an int and a long: ”);
• scanf(“%i %li”, &I, &l);
• printf(“Your int is %i and long is %linn”, i,l);
•
• printf(“Now, enter values for float and a double: ”);
• scanf(“%f %f”, &f, &d);
• printf(“Your float is %f and double is %fnn”, f,d);
• }
Output:
Enter value for an int and a long: 524 79735
Your int is 524 and long is 79735
Program 4-1.3
• #include<stdio.h>
• void main(){
• int x, y, sum;
• float quotient;
• printf(“Enter a number: “);
• scanf(“%i”, &x);
• printf(“Enter another number: ”);
• scanf(“%i”, &y);
• sum = x + y;
• printf(“Sum: %”, sum);
• }
Relational Operators
Operator symbol Operator function/Meaning
< Is less than to
> Is greater than to
<= Is less than or equal to
>= Is greater than or equal to
== Is equal to
!= Not equal to
Ex.
x = 45; -> the value of variable x is equal to 45
y = 40; -> the value of variable y is equal to 40
y==x -> is y equal to x?
x<=y -> is x less than or equal to y?
x!=y -> is x not equal to y?
Logical Operators
Operator
Symbol
Operator
function/Meani
ng
|| OR
&& AND
! Logical Not
RULES:
OR Operator AND Operator
True || True = True
True || False = True
False || True = True
False || False = False
True && True = True
True && False = False
False && True = False
False && False = False
The Three Control Structures or
program constructs:
• Sequence – The instructions are executed in a
serial manner, one after another.
• Selection – It provides a decision point that
enables the program to choose one between
two or more pathways.
• Iteration – Repeats a set of instructions a
number of times based on the condition
stated.
Sequence
Example:
#include<stdio.h>
main(){
int number;
printf(“Enter a number: ”);
scanf(“%i”, &number);
printf(“You entered %i”, number);
}
Selection
If & else statement
Syntax:
Single if – the ody of if statement will be
executed only if the condition’s.
Syntax:
if(condition){
statement/body;
}
Example:
#include<stdio.h>
#include<conio.h>
main(){
int x;
printf(“Enter number: ”);
scanf(“%i”, &x);
if(x>=5){
printf(“You entered a value greater than four”);
}
getch();
}
If & else – the body of “if” will be executed if the
condition’s outcome is true, if false, the body of “else”
statement will be executed.
Syntax:
if(condition){
body/statement;
}
Else{
Body/statement;
}
Example:
#include<stdio.h>
#include<conio.h>
main(){
int grade;
printf(“Enter number: ”);
scanf(“%i”, &grade);
if(grade>=5){
printf(“You Passed.”);
}
else{
printf(“You failed.”);
}
getch();
}
If, else if & else – if the condition’s outcome of
“if” statement is true, its body will be executed
but if not it will test the condition of “else if”
statement, if it is true it will be executed and if
not it will execute the body of “else” statement
Example
#include<stdio.h>
#include<conio.h>
main(){
int x;
printf(“Enter number from 1 - 3: ”);
scanf(“%i”, &x);
if(x==1){
printf(“You entered one”);
}
else if(number==2){
printf(“You entered two”);
}
else if(number==3){
printf(“You entered three”);
}
else{
printf(“Invalid Input!”);
}
getch();
}
Switch case statement
Syntax:
switch(basis){
case 1: statement;
break;
case 2: statement;
break;
case n: statement:
break;
default: statement;
break;
}
Example
#include<stdio.h>
#include<conio.h>
main(){
int x;
printf(“Enter a number from 1 - 3: ”);
scanf(“%i”, &x);
switch(x){
case 1: printf(“you entered one”); break;
case 2: printf(“you entered two”); break;
case 3: printf(“you entered three”); break;
default: printf(“invalid input”); break;
}
getch();
}
Iteration
Pre-test Loop - while loop is a control
flow statement that allows code to be executed
repeatedly based on a given Boolean condition. The
while loop can be thought of as a repeating if
statement.The while construct consists of a block of
code and a condition. The condition is evaluated,
and if the condition is true, the code within the
block is executed. This repeats until the condition
becomes false. Because while loop checks the
condition before the block is executed.
Syntax:
while(condition){
statement;
}
Program 4-1.5
#include<stdio.h>
#include<conio.h>
main(){
int x=1;
while(x<=5){
printf(“%i ”,x);
x=x+1;
}
getch();
}
Post-test Loop - is a control flow statement that
allows code to be executed repeatedly based on
a given Boolean condition. The do
while construct consists of a block of code and a
condition. First, the code within the block is
executed, and then the condition is evaluated. If
the condition is true the code within the block is
executed again. This repeats until the condition
becomes false. Because do while loops check
the condition after the block is executed.
Syntax:
do{
statement;
} while(condition);
Program 4-1.6:
Example:
#include<stdio.h>
#include<conio.h>
main(){
int x=1;
do {
printf(“%i ”,x);
x=x+1;
} while(x<=5);
getch();
}
Counter-controlled Loop syntax – is a
programming statement which allows code to be
repeatedly executed. Unlike many other kinds of loops,
such as the while loop, the for loop is often distinguished
by an explicit loop counter or loop variable. This allows
the body of the for loop (the code that is being
repeatedly executed) to know about the sequencing of
each iteration. For loops are also typically used when the
number of iterations is known before entering the loop.
For loops are shorthand way to make loops when the
number of iterations is known, as a for loop can be
written as a while loop.
Syntax:
for(initialization;condition;counter){
statement;
}
Program 4-1.7
Example:
#include<stdio.h>
#include<conio.h>
main(){
int x;
for(x=1;x<=5;x++) {
printf(“%i ”,x);
}
getch();
}
Activity Challenge
/* Displaying Fibonacci sequence up to nth term
where n is entered by user. */

More Related Content

What's hot

Control Structures
Control StructuresControl Structures
Control Structures
Ghaffar Khan
 

What's hot (20)

Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
Control Structures
Control StructuresControl Structures
Control Structures
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
C if else
C if elseC if else
C if else
 
Decision Control Structure If & Else
Decision Control Structure If & ElseDecision Control Structure If & Else
Decision Control Structure If & Else
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Structure in programming in c or c++ or c# or java
Structure in programming  in c or c++ or c# or javaStructure in programming  in c or c++ or c# or java
Structure in programming in c or c++ or c# or java
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
 
C programming decision making
C programming decision makingC programming decision making
C programming decision making
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 

Similar to Bsit1

Branching statements
Branching statementsBranching statements
Branching statements
ArunMK17
 

Similar to Bsit1 (20)

unit 2-Control Structures.pptx
unit 2-Control Structures.pptxunit 2-Control Structures.pptx
unit 2-Control Structures.pptx
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CINPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
 
Branching statements
Branching statementsBranching statements
Branching statements
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
 
CONTROL FLOW in C.pptx
CONTROL FLOW in C.pptxCONTROL FLOW in C.pptx
CONTROL FLOW in C.pptx
 
Session 3
Session 3Session 3
Session 3
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in CSPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
 
control statement
control statement control statement
control statement
 
Module 2- Control Structures
Module 2- Control StructuresModule 2- Control Structures
Module 2- Control Structures
 
Control statements-Computer programming
Control statements-Computer programmingControl statements-Computer programming
Control statements-Computer programming
 
C Unit-2.ppt
C Unit-2.pptC Unit-2.ppt
C Unit-2.ppt
 
C programming
C programmingC programming
C programming
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Looping
LoopingLooping
Looping
 

More from jigeno

Basic introduction to ms access
Basic introduction to ms accessBasic introduction to ms access
Basic introduction to ms access
jigeno
 
16 logical programming
16 logical programming16 logical programming
16 logical programming
jigeno
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
jigeno
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
jigeno
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
jigeno
 
13 concurrency
13 concurrency13 concurrency
13 concurrency
jigeno
 
12 object oriented programming
12 object oriented programming12 object oriented programming
12 object oriented programming
jigeno
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data types
jigeno
 
9 subprograms
9 subprograms9 subprograms
9 subprograms
jigeno
 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structure
jigeno
 
7 expressions and assignment statements
7 expressions and assignment statements7 expressions and assignment statements
7 expressions and assignment statements
jigeno
 
6 data types
6 data types6 data types
6 data types
jigeno
 
5 names
5 names5 names
5 names
jigeno
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
jigeno
 
3 describing syntax and semantics
3 describing syntax and semantics3 describing syntax and semantics
3 describing syntax and semantics
jigeno
 
2 evolution of the major programming languages
2 evolution of the major programming languages2 evolution of the major programming languages
2 evolution of the major programming languages
jigeno
 
1 preliminaries
1 preliminaries1 preliminaries
1 preliminaries
jigeno
 
Access2007 m2
Access2007 m2Access2007 m2
Access2007 m2
jigeno
 
Access2007 m1
Access2007 m1Access2007 m1
Access2007 m1
jigeno
 

More from jigeno (20)

Access2007 part1
Access2007 part1Access2007 part1
Access2007 part1
 
Basic introduction to ms access
Basic introduction to ms accessBasic introduction to ms access
Basic introduction to ms access
 
16 logical programming
16 logical programming16 logical programming
16 logical programming
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
 
13 concurrency
13 concurrency13 concurrency
13 concurrency
 
12 object oriented programming
12 object oriented programming12 object oriented programming
12 object oriented programming
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data types
 
9 subprograms
9 subprograms9 subprograms
9 subprograms
 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structure
 
7 expressions and assignment statements
7 expressions and assignment statements7 expressions and assignment statements
7 expressions and assignment statements
 
6 data types
6 data types6 data types
6 data types
 
5 names
5 names5 names
5 names
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
 
3 describing syntax and semantics
3 describing syntax and semantics3 describing syntax and semantics
3 describing syntax and semantics
 
2 evolution of the major programming languages
2 evolution of the major programming languages2 evolution of the major programming languages
2 evolution of the major programming languages
 
1 preliminaries
1 preliminaries1 preliminaries
1 preliminaries
 
Access2007 m2
Access2007 m2Access2007 m2
Access2007 m2
 
Access2007 m1
Access2007 m1Access2007 m1
Access2007 m1
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 

Bsit1