SlideShare a Scribd company logo
Programming with C
TAKING INPUT
PREPARED BY: FARIA TABASSUM
FARIA.TABASSUM@CUB.EDU.BD
The scanf() function
 To take input from the user we need to use the scanf function
 The scanf() function is used to read any characters, strings and numeric
values from the keyboard
PREPARED BY: FARIA TABASSUM
FARIA.TABASSUM@CUB.EDU.BD
2
Basic format
scanf (“format string”, variable list);
 Format string basically denotes the type of data that we want to take
as input
 In the variable list we type in the names of the variables separated by
comma (,) and preceded by ampersand (&) symbol.
PREPARED BY: FARIA TABASSUM
FARIA.TABASSUM@CUB.EDU.BD
3
scanf for different data types
Integer:
int value;
scanf (“%d”, &value)
Float:
float value;
scanf (“%f”, &value);
Char:
char ch;
scanf (“%c”, &ch);
PREPARED BY: FARIA TABASSUM
FARIA.TABASSUM@CUB.EDU.BD
4
Multiple variables as input
We can take multiple variables as input by separating them with
commas.
PREPARED BY: FARIA TABASSUM
FARIA.TABASSUM@CUB.EDU.BD
5
1 2
Multiple variables as input
We can take multiple variables as input by separating them with a
comma.
PREPARED BY: FARIA TABASSUM
FARIA.TABASSUM@CUB.EDU.BD
6
1 2
1 and 2 are the same. Follow any method you want
Example
Write a C program that takes an integer number as input and print the
value of that number.
PREPARED BY: FARIA TABASSUM
FARIA.TABASSUM@CUB.EDU.BD
7
Example
Write a C program that takes three character variables as input and
print them in reverse order.
PREPARED BY: FARIA TABASSUM
FARIA.TABASSUM@CUB.EDU.BD
8
THE END
PREPARED BY: FARIA TABASSUM
FARIA.TABASSUM@CUB.EDU.BD
9

More Related Content

Similar to Lecture_4-Taking Inputs.pptx

Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
Bharat17485
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners
ShreyaSingh291866
 
U4.ppt
U4.pptU4.ppt
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
Bhavik Vashi
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
trupti1976
 
C data type format specifier
C data type format specifierC data type format specifier
C data type format specifier
Sandip Sitäulä
 
string , pointer
string , pointerstring , pointer
string , pointer
Arafat Bin Reza
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
Muthuganesh S
 
Managing Input Output Operations
Managing Input Output OperationsManaging Input Output Operations
Managing Input Output Operations
Munazza-Mah-Jabeen
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
niyamathShariff
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
Basic Input and Output
Basic Input and OutputBasic Input and Output
Basic Input and Output
Nurul Zakiah Zamri Tan
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
Presention programming
Presention programmingPresention programming
Presention programming
saleha iqbal
 
Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in C
Abinaya B
 
Data Input and Output
Data Input and OutputData Input and Output
Data Input and Output
Sabik T S
 
T03 b basicioscanf
T03 b basicioscanfT03 b basicioscanf
T03 b basicioscanf
teach4uin
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
yazad dumasia
 
Variadic functions
Variadic functionsVariadic functions
Variadic functions
ramyaranjith
 

Similar to Lecture_4-Taking Inputs.pptx (20)

Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners
 
U4.ppt
U4.pptU4.ppt
U4.ppt
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
C data type format specifier
C data type format specifierC data type format specifier
C data type format specifier
 
string , pointer
string , pointerstring , pointer
string , pointer
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
 
Managing Input Output Operations
Managing Input Output OperationsManaging Input Output Operations
Managing Input Output Operations
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 
Basic Input and Output
Basic Input and OutputBasic Input and Output
Basic Input and Output
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 
Presention programming
Presention programmingPresention programming
Presention programming
 
Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in C
 
Data Input and Output
Data Input and OutputData Input and Output
Data Input and Output
 
T03 b basicioscanf
T03 b basicioscanfT03 b basicioscanf
T03 b basicioscanf
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
Variadic functions
Variadic functionsVariadic functions
Variadic functions
 

Recently uploaded

KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabhQuarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
aisafed42
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLESINTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
anfaltahir1010
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
ervikas4
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
Tier1 app
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
ISH Technologies
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
Kubernetes at Scale: Going Multi-Cluster with Istio
Kubernetes at Scale:  Going Multi-Cluster  with IstioKubernetes at Scale:  Going Multi-Cluster  with Istio
Kubernetes at Scale: Going Multi-Cluster with Istio
Severalnines
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 

Recently uploaded (20)

KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabhQuarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLESINTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
INTRODUCTION TO AI CLASSICAL THEORY TARGETED EXAMPLES
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptxMigration From CH 1.0 to CH 2.0 and  Mule 4.6 & Java 17 Upgrade.pptx
Migration From CH 1.0 to CH 2.0 and Mule 4.6 & Java 17 Upgrade.pptx
 
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSISDECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
DECODING JAVA THREAD DUMPS: MASTER THE ART OF ANALYSIS
 
Preparing Non - Technical Founders for Engaging a Tech Agency
Preparing Non - Technical Founders for Engaging  a  Tech AgencyPreparing Non - Technical Founders for Engaging  a  Tech Agency
Preparing Non - Technical Founders for Engaging a Tech Agency
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
Kubernetes at Scale: Going Multi-Cluster with Istio
Kubernetes at Scale:  Going Multi-Cluster  with IstioKubernetes at Scale:  Going Multi-Cluster  with Istio
Kubernetes at Scale: Going Multi-Cluster with Istio
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 

Lecture_4-Taking Inputs.pptx

  • 1. Programming with C TAKING INPUT PREPARED BY: FARIA TABASSUM FARIA.TABASSUM@CUB.EDU.BD
  • 2. The scanf() function  To take input from the user we need to use the scanf function  The scanf() function is used to read any characters, strings and numeric values from the keyboard PREPARED BY: FARIA TABASSUM FARIA.TABASSUM@CUB.EDU.BD 2
  • 3. Basic format scanf (“format string”, variable list);  Format string basically denotes the type of data that we want to take as input  In the variable list we type in the names of the variables separated by comma (,) and preceded by ampersand (&) symbol. PREPARED BY: FARIA TABASSUM FARIA.TABASSUM@CUB.EDU.BD 3
  • 4. scanf for different data types Integer: int value; scanf (“%d”, &value) Float: float value; scanf (“%f”, &value); Char: char ch; scanf (“%c”, &ch); PREPARED BY: FARIA TABASSUM FARIA.TABASSUM@CUB.EDU.BD 4
  • 5. Multiple variables as input We can take multiple variables as input by separating them with commas. PREPARED BY: FARIA TABASSUM FARIA.TABASSUM@CUB.EDU.BD 5 1 2
  • 6. Multiple variables as input We can take multiple variables as input by separating them with a comma. PREPARED BY: FARIA TABASSUM FARIA.TABASSUM@CUB.EDU.BD 6 1 2 1 and 2 are the same. Follow any method you want
  • 7. Example Write a C program that takes an integer number as input and print the value of that number. PREPARED BY: FARIA TABASSUM FARIA.TABASSUM@CUB.EDU.BD 7
  • 8. Example Write a C program that takes three character variables as input and print them in reverse order. PREPARED BY: FARIA TABASSUM FARIA.TABASSUM@CUB.EDU.BD 8
  • 9. THE END PREPARED BY: FARIA TABASSUM FARIA.TABASSUM@CUB.EDU.BD 9