SlideShare a Scribd company logo
1 of 21
DATA INPUT AND 
OUTPUT 
1
• Define input output statements 
• Explain function of input output 
2 
statements 
• Create and modify input output 
file in programme
3
4 
C Environment
C environment 
input device output device 
5 
error device 
stdin 
stdout 
stderr
input/output operation take places as a stream 
of character 
#include<stdio.h> includes the contents of 
standard input-output file, stdio.h at compile 
time (contains definitions of stdin, stdout, 
stderr) 
6
 C provides standard functions, scanf() and 
printf() for performing formatted input and 
output 
 Input data may contain a mixed mode data: 
7 
DATA TYPES EXAMPLE 
float floating point 101.7, 0.5, 2.36 
double floating point 2.365, 75.666, 0.12222 
int decimal number 225, 3, 75, 9662 
char character a, f, apple, 15DET09F1002
 printf() and puts() 
printf() function 
used for formatted output to standard output 
device that is screen 
general form: 
printf(“format_specifier”,variable_list1,variable_list2,…) 
e.g: 
printf(“%d%d%dn”,456,456,456) 
Output: 456456456 
8
9 
Codes Meaning 
b Back space 
f Form feed 
n New line 
r Carriage return 
t Horizontal tab 
” Double quote mark 
’ Single quote mark 
0 Null 
 Back slash 
v Vertical tab 
a Alert 
o Octal constant 
x Hexadecimal constants
puts() 
to display a string contained in a string 
variable 
general form: 
e.g: 
char str[20]=“I am going to England”; 
puts(str); 
if str has the string “I am going to Englad”, puts(str) would 
display the entire string “I am going to England” and 
moves the cursor to the beginning of the next line 
10 
int puts (char*)
 scanf() and gets() 
scanf() function 
used for formatted input from standard input 
device that is keyboard 
general form: 
scanf(“format specifier”,variable_list1,variable_list2,…) 
e.g: 
printf(“Please enter a number”); 
scanf(“%d”,&number1) 
Output: Please enter a number 15 
11
gets() 
to accept string up to a new line character into 
a string variable 
general form: 
12 
char*gets (char *);
 To illustrate gets() and puts() 
13 
#include<stdio.h> 
#include<conio.h> 
void main() 
{ 
char words[40]; 
clrscr(); 
printf(“Enter a line of text: “); 
gets (words); 
printf(“nThe line of text entered is “); 
puts (words); 
} 
Enter a line of text: I love programming 
The line of text entered is I love programming
14 
printf() STATEMENT OUTPUT 
printf(“Line 1”); 
printf(“Line 2”); 
Line1Line2Line3 
printf(“Line 3”); 
The newline character (n) must be include whenever 
the cursor have to move to the next line 
printf() STATEMENT OUTPUT 
printf(“Line 1n”); 
Line1 
printf(“Line 2n”); 
Line2 
printf(“Line 3n”); 
Line3 
printf() STATEMENT OUTPUT 
printf(“Line 1”); 
Line1 
printf(“nLine 2n”); 
Line2 
printf(“Line 3”); 
Line3
 Specifies the field in which the data has to 
be entered 
15 
code meaning 
%c Single character 
%d Decimal integer 
%e Floating point value 
%f Floating point value 
%o Octal value 
%x Hexadecimal value 
%s A string 
%u Unsigned integer
 int d; 
to accept a value into a variable n of int type 
scanf(“%d”,&n); Which is %d is the format specifier for int 
16 
Variable n 
 char c; 
to accept a value into a variable c of char type 
scanf(“%c”, &c); Note that the format specified used is %c 
Variable c
 float f; 
to accept a floating point value into the variable f 
scanf(“%f”, &f); Note that the format specified used is %f 
17 
Variable f 
 To read values into three variable i, f, and c of 
type int, float and char using a single statement 
scanf(“%d%f%c”, &i, 
&f, &c); 
Note that the order of the format 
specifiers matches with that of the 
variable
 int d; 
To display the value of the variable n of int type 
printf(“%d”,n); Which is %d is the format specifier for int 
18 
Variable n 
 char c; 
To display the character stored in the variable c 
printf(“%c”,c); Note that the format specified used is %c 
Variable c
 float f; 
to display the floating point value stored in the 
variable f 
printf(“%f”,f); Note that the format specified used is %f 
19 
Variable f 
 To display the value stored in three variable i, f, 
and c of type int, float and char using a single 
statement 
printf(“%d%f%c”,i,f, 
c); 
Note that the order of the format 
specifiers matches with that of the 
variable
 To illustrate simple printf() and scanf() 
Enter first number : 15 
Enter second number :65 
Total for first and second number :80 
20 
#include<stdio.h> 
void main() 
{ 
int number_1, number_2, total; 
printf(“Enter first number: “); 
scanf(“%d”, &number_1); 
printf(“Enter second number: “); 
scanf(“%d”, &number_2); 
total= number_1 + number_2; 
printf(“nTotal for first and second number : %d”, total); 
}
21

More Related Content

What's hot

Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in CMuthuganesh S
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7Rumman Ansari
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6Rumman Ansari
 
C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2Rumman Ansari
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9Rumman Ansari
 
7. input and output functions
7. input and output functions7. input and output functions
7. input and output functionsWay2itech
 
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshopneosphere
 
9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function웅식 전
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8Rumman Ansari
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branchingSaranya saran
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in cSaranya saran
 
Input and output in c
Input and output in cInput and output in c
Input and output in cRachana Joshi
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumpingMomenMostafa
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointersMomenMostafa
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11Rumman Ansari
 

What's hot (20)

Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
 
5 format
5 format5 format
5 format
 
C Programming Language Part 7
C Programming Language Part 7C Programming Language Part 7
C Programming Language Part 7
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
 
C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2C Programming Language Step by Step Part 2
C Programming Language Step by Step Part 2
 
C Programming Language Part 9
C Programming Language Part 9C Programming Language Part 9
C Programming Language Part 9
 
7. input and output functions
7. input and output functions7. input and output functions
7. input and output functions
 
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshop
 
9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function
 
input
inputinput
input
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
First c program
First c programFirst c program
First c program
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
Input and output in c
Input and output in cInput and output in c
Input and output in c
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
 
C Programming Language Part 11
C Programming Language Part 11C Programming Language Part 11
C Programming Language Part 11
 

Viewers also liked

Dbs 1012 synopsis
Dbs 1012 synopsisDbs 1012 synopsis
Dbs 1012 synopsismohd_mizan
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++Nilesh Dalvi
 
Communicative English 3 Mini Project
Communicative English 3 Mini ProjectCommunicative English 3 Mini Project
Communicative English 3 Mini ProjectFran Siskah Doremon
 

Viewers also liked (6)

Dbs 1012 synopsis
Dbs 1012 synopsisDbs 1012 synopsis
Dbs 1012 synopsis
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Communicative English 3 Mini Project
Communicative English 3 Mini ProjectCommunicative English 3 Mini Project
Communicative English 3 Mini Project
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Mini project complete
Mini project completeMini project complete
Mini project complete
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 

Similar to CHAPTER 4

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 Functionimtiazalijoono
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C LanguageAdnan Khan
 
2. introduction of a c program
2. introduction of a c program2. introduction of a c program
2. introduction of a c programAlamgir Hossain
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’eShikshak
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners ShreyaSingh291866
 
Presention programming
Presention programmingPresention programming
Presention programmingsaleha iqbal
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingMd. Ashikur Rahman
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 FocJAYA
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)Saifur Rahman
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxAnkitaVerma776806
 
Chap 2 input output dti2143
Chap 2  input output dti2143Chap 2  input output dti2143
Chap 2 input output dti2143alish sha
 

Similar to CHAPTER 4 (20)

Introduction to Input/Output Functions in C
Introduction to Input/Output Functions in CIntroduction to Input/Output Functions in C
Introduction to Input/Output Functions in C
 
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
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
 
Unit 2- Module 2.pptx
Unit 2- Module 2.pptxUnit 2- Module 2.pptx
Unit 2- Module 2.pptx
 
2. introduction of a c program
2. introduction of a c program2. introduction of a c program
2. introduction of a c program
 
Tut1
Tut1Tut1
Tut1
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
Presention programming
Presention programmingPresention programming
Presention programming
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
 
Lecture 8- Data Input and Output
Lecture 8- Data Input and OutputLecture 8- Data Input and Output
Lecture 8- Data Input and Output
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
Chap 2 input output dti2143
Chap 2  input output dti2143Chap 2  input output dti2143
Chap 2 input output dti2143
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
string , pointer
string , pointerstring , pointer
string , pointer
 
Programming in C.pptx
Programming in C.pptxProgramming in C.pptx
Programming in C.pptx
 

More from mohd_mizan

More from mohd_mizan (7)

Mind map chapter 4
Mind map chapter 4Mind map chapter 4
Mind map chapter 4
 
Chapter 4 work, energy and power
Chapter 4 work, energy and powerChapter 4 work, energy and power
Chapter 4 work, energy and power
 
CHAPTER 3
CHAPTER 3CHAPTER 3
CHAPTER 3
 
CHAPTER 6
CHAPTER 6CHAPTER 6
CHAPTER 6
 
CHAPTER 5
CHAPTER 5CHAPTER 5
CHAPTER 5
 
CHAPTER 2
CHAPTER 2CHAPTER 2
CHAPTER 2
 
CHAPTER 1
CHAPTER 1CHAPTER 1
CHAPTER 1
 

Recently uploaded

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Recently uploaded (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

CHAPTER 4

  • 1. DATA INPUT AND OUTPUT 1
  • 2. • Define input output statements • Explain function of input output 2 statements • Create and modify input output file in programme
  • 3. 3
  • 5. C environment input device output device 5 error device stdin stdout stderr
  • 6. input/output operation take places as a stream of character #include<stdio.h> includes the contents of standard input-output file, stdio.h at compile time (contains definitions of stdin, stdout, stderr) 6
  • 7.  C provides standard functions, scanf() and printf() for performing formatted input and output  Input data may contain a mixed mode data: 7 DATA TYPES EXAMPLE float floating point 101.7, 0.5, 2.36 double floating point 2.365, 75.666, 0.12222 int decimal number 225, 3, 75, 9662 char character a, f, apple, 15DET09F1002
  • 8.  printf() and puts() printf() function used for formatted output to standard output device that is screen general form: printf(“format_specifier”,variable_list1,variable_list2,…) e.g: printf(“%d%d%dn”,456,456,456) Output: 456456456 8
  • 9. 9 Codes Meaning b Back space f Form feed n New line r Carriage return t Horizontal tab ” Double quote mark ’ Single quote mark 0 Null Back slash v Vertical tab a Alert o Octal constant x Hexadecimal constants
  • 10. puts() to display a string contained in a string variable general form: e.g: char str[20]=“I am going to England”; puts(str); if str has the string “I am going to Englad”, puts(str) would display the entire string “I am going to England” and moves the cursor to the beginning of the next line 10 int puts (char*)
  • 11.  scanf() and gets() scanf() function used for formatted input from standard input device that is keyboard general form: scanf(“format specifier”,variable_list1,variable_list2,…) e.g: printf(“Please enter a number”); scanf(“%d”,&number1) Output: Please enter a number 15 11
  • 12. gets() to accept string up to a new line character into a string variable general form: 12 char*gets (char *);
  • 13.  To illustrate gets() and puts() 13 #include<stdio.h> #include<conio.h> void main() { char words[40]; clrscr(); printf(“Enter a line of text: “); gets (words); printf(“nThe line of text entered is “); puts (words); } Enter a line of text: I love programming The line of text entered is I love programming
  • 14. 14 printf() STATEMENT OUTPUT printf(“Line 1”); printf(“Line 2”); Line1Line2Line3 printf(“Line 3”); The newline character (n) must be include whenever the cursor have to move to the next line printf() STATEMENT OUTPUT printf(“Line 1n”); Line1 printf(“Line 2n”); Line2 printf(“Line 3n”); Line3 printf() STATEMENT OUTPUT printf(“Line 1”); Line1 printf(“nLine 2n”); Line2 printf(“Line 3”); Line3
  • 15.  Specifies the field in which the data has to be entered 15 code meaning %c Single character %d Decimal integer %e Floating point value %f Floating point value %o Octal value %x Hexadecimal value %s A string %u Unsigned integer
  • 16.  int d; to accept a value into a variable n of int type scanf(“%d”,&n); Which is %d is the format specifier for int 16 Variable n  char c; to accept a value into a variable c of char type scanf(“%c”, &c); Note that the format specified used is %c Variable c
  • 17.  float f; to accept a floating point value into the variable f scanf(“%f”, &f); Note that the format specified used is %f 17 Variable f  To read values into three variable i, f, and c of type int, float and char using a single statement scanf(“%d%f%c”, &i, &f, &c); Note that the order of the format specifiers matches with that of the variable
  • 18.  int d; To display the value of the variable n of int type printf(“%d”,n); Which is %d is the format specifier for int 18 Variable n  char c; To display the character stored in the variable c printf(“%c”,c); Note that the format specified used is %c Variable c
  • 19.  float f; to display the floating point value stored in the variable f printf(“%f”,f); Note that the format specified used is %f 19 Variable f  To display the value stored in three variable i, f, and c of type int, float and char using a single statement printf(“%d%f%c”,i,f, c); Note that the order of the format specifiers matches with that of the variable
  • 20.  To illustrate simple printf() and scanf() Enter first number : 15 Enter second number :65 Total for first and second number :80 20 #include<stdio.h> void main() { int number_1, number_2, total; printf(“Enter first number: “); scanf(“%d”, &number_1); printf(“Enter second number: “); scanf(“%d”, &number_2); total= number_1 + number_2; printf(“nTotal for first and second number : %d”, total); }
  • 21. 21