SlideShare a Scribd company logo
By: Prof. Adnan Faisal Khan
By: Prof. Adnan Faisal Khan
CHAPTER 10
Standard Input
• Standard input refers to the input using keyboard
• A program may need certain input from the user
• C language provides many functions to get intput from the user:
• scanf()
• gets()
• getch()
• getche()
• Include the header file <stdio.h> in program to call scanf() and gets()
and include the header file <conio.h> in program to call getch() and
getche() function.
Standard Output
• The term standard output refers to the output displayed on the monitor
• The result of a program is called the out of the program
• C language provides many functions to display program output to the
user
• Printf()
• Puts()
• Include the header file <stdio.h> in program to call printf() and puts()
printf ( ) function
• The printf function is used to display output on the monitor
• It can display text, constants, values of variables or expressions on
monitor in specified format:
Syntax: printf (Format String, argument_list);
Format String Argument list
• Also called control string
• Give in double quotes
• May consist of the following:
• Text
• Format specifiers
• Escape sequence
• Consists of constants, variable
or expression are to be printed
on the screen
• Separated by comma
• Use of argument list is
optional
• Using Format String without Argument List
printf(“Hello World”);
Control String
• Using Format String with Single Argument
int m =80;
printf(“ Your marks are %d”, m);
Control String
• Using Format String with Multiple Arguments
int m=80;
char c=‘A’;
• Printf(“your marks are %d and grade %c”, m, c);
• One printf can print several lines by using newline escape sequence – ‘n’
printf( “ Welcome n to n C “);
Format strings can have
multiple format specifier, if
you are printing multiple
values
Program 10.1
Write a program that displays a message and values of integer and character
variables.
#include<stdio.h>
#include<conio.h>
void main()
{
int n=10;
char ch='*';
clrscr();
printf("Testing Output...");
printf("%d",n);
printf("%c",ch);
getch();
}
Program 10.2
Write a program that adds two floating point numbers and shows the
sum on the screen
#include<stdio.h>
#include<conio.h>
void main()
{
float a=2.5,b=3.0,sum;
sum = a+ b;
clrscr();
printf(“%f + %f = %f ”,a,b,sum);
getch();
}
Program 10.3
Write a program that calculate and print area of square with given height and width
#include<stdio.h>
#include<conio.h>
void main()
{
int area,h,w;
h=2;
w=4;
area= h *w;
printf(“Area of square is %d”,area);
// printf(“ Area of square is %d when height is %d and width is %d”,area,h,w);
getch();
}
Format Specifier
• Format specifier is used to specify the format according to which values
will be read and display
• It determines the following things:
• Data type of Variable
• Field width
• Format of the value
• Format specifier is started with symbol %
• Different format specifiers are used with different types of variable
• Integer format specifier
• Character format specifier
• Floating Point format specifier
3 4 5 1
3 4 5 1
Format Specifier
• Integer Format Specifier
Format Specifier Type
%d Used for signed decimal integer value
%i Used for signed integer value
%o Used for unsigned octal value
%u Used for unsigned integer value
%x Used for unsigned hexadecimal value with lower case like a,b,c
etc.
%X Used for unsigned hexadecimal value with Upper case like A,B,C
etc.
Format Specifier (Cont..)
• Floating-Point Format Specifier
• Character Format Specifier
Format Specifier Type
%f Used for signed floating point value
%e Used for exponent value
%g Used for short notation value
Format Specifier Type
%c Used for character value
%s Used for strings
How integer values are printed in C language?
• The format specifier %d is used to display integer values in printf
functions.
• If an integer variable m contains 100 value then it can print by
following statement:
printf(“Your marks are %d”, m);
output:
Your marks are 100
How floating point values are printed in C
language?
• The format specifier %f is used to display floating point value in printf
function.
• If an value of float variable a is 90.55 . The following statement:
printf(“Average marks are %f”, a);
output:
Average marks are 90.550000
Field width Specifier
Field Width specifier for integer
• %d format specifier is used to display integer value in printf function
• A value can be written between % and d in “%d” format specified
Example
int area =25;
printf(“Area = %4d”,area);
• The value will appear right-justified and two spaces will appear before the actual
value
Specifying width and precision for floating point
value
Programs From
10.4 to 10.8 from book
Escape Sequence
• Special characters used in format string to modify the format
of output
• Character are not displayed in the output
• Always begin with backslash “”.
• Backslash is called an escape character
Escape sequence Character represented
b Backspace
f Form Feed
n New Line
r Carriage return
t Tab
’ Single quote
” Double quote
xdd
ASCII code in hexadecimal notation. Each d represent
digit
ddd ASCII code in octal notation. Each d represents a digit
• b use to insert backspace in the output
• f (Form Feed page break)
• n (New line) – We use it to shift the cursor control to the new line
printf(
• r (Carriage Return) – We use it to position the cursor to the
beginning of the current line.
• t (Horizontal tab) – We use it to shift the cursor to a couple of spaces
to the right in the same line.
• ’ (Apostrophe or single quotation mark) – We use it to display the
single-quotation mark.
• ” (Double quotation mark) – We use it to display the double-
quotation mark.
•  (Backslash) – We use it to display the backslash character.
• a (Audible bell) – A beep is generated indicating the execution of the
program to alert the user.
Programs From
10.9 to 10.11 from book
Scanf Function
• Read data from the standard input device ( Usually Keyboard) and
store it in a variable
• Requires stdio.h header file used to read input from keyboard
• Syntax
• scanf(“format string”, &variable);
Programs From 10.12 to
10.22 from book
Character Input
• Scanf function can be used for character input
• Scanf function is not suitable for all situations, specially when enter
key is not require on any input ( e.g. arrow keys in games)
• Specialized function for character input are available
• getch()
• getche()
• These functions are part of conio.h library file
getch()
• The getch function is used to input single character from the user
• Requires conio.h header file to use this function
• When this function is executed, it waits for any key to be pressed
• Character entered by the user is not displayed on the screen
• The function is frequently used to pause program execution
Syntax: [var =] getch();
Variable It indicates the variable in which the character is stored. The
use of variable is optional
Program 10.23
#include<stdio.h>
#include<conio.h>
Void main()
{
char c;
clrscr();
printf(“ Enter Character ”);
c= getch();
printf(“n You Entered %c”,c);
getch();
}
Enter Character
You Entered s
Output
getche()
• The getche() function is used to input single character from the user
• Requires conio.h header file to use this function
• When this function is executed, it waits for any key to be pressed
• Character entered by the user displayed on the screen
Syntax: [var =] getche();
Variable It indicates the variable in which the character is stored. The
use of variable is optional
Program 10.24
#include<stdio.h>
#include<conio.h>
Void main()
{
char c;
clrscr();
printf(“ Enter Character ”);
c= getche();
printf(“n You Entered %c”,c);
getch();
}
Enter Character s
You Entered s
Output
gets() Function
• Used to input string value from the user.
• User press Enter key and string is stored variable
• The null character is automatically entered at the end of string
• Requires stdio.h header file to use this function
Syntax: gets( String_Variable );
Example printf(“Enter a string”);
gets(str);
Suppose if user input “Pakistan” then the string will stores in str as follows:
P a k i s t a n 0
puts() Function
• Used to display string on the screen.
• It can display a string constant or string variable
• Requires stdio.h header file to use this function
Syntax: puts( parameter );
Parameter It indicates the string variable in which the string is stored.
In case of string constant, it is written in double quotes
Example puts(str);
• Program 10.25
Write a program that inputs a string and displays it on a screen
#include<stdio.h>
#include<conio.h>
void main()
{
char book[ 50];
clrscr();
printf(“Enter name of your favorit book”);
gets(book);
printf(“Your favorite book is”);
puts(book);
getch();
}
Enter name of your favourite book : Holy Quran
Your favourite book is : Holy Quran
clrscr() Function
• Used to clear screen
• after clear the screen cursor blinks on the top-left corner
• Requires conio.h header file to use this function
Syntax: clrscr();
sizeof Operator
• Used to find the size of any data value
• Its give the number of bytes occupied by that value
Syntax: sizeof(operand);
Examples : sizeof(10);
sizeof(4.5);
sizeof(“Pakistan”);
sizeof(‘A’);
Input and Output In C Language
Input and Output In C Language
Input and Output In C Language

More Related Content

What's hot

Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
 
String in c
String in cString in c
String in c
Suneel Dogra
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
tanmaymodi4
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
C program compiler presentation
C program compiler presentationC program compiler presentation
C program compiler presentation
Rigvendra Kumar Vardhan
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 
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
SowmyaJyothi3
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming9
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
yndaravind
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
Ashim Lamichhane
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 
Printf and scanf
Printf and scanfPrintf and scanf
Printf and scanf
gidc engineering college
 
C functions
C functionsC functions

What's hot (20)

Functions in C
Functions in CFunctions in C
Functions in C
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
String in c
String in cString in c
String in c
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
C program compiler presentation
C program compiler presentationC program compiler presentation
C program compiler presentation
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
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
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Strings in C
Strings in CStrings in C
Strings in C
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
C programming - String
C programming - StringC programming - String
C programming - String
 
Printf and scanf
Printf and scanfPrintf and scanf
Printf and scanf
 
C functions
C functionsC functions
C functions
 

Similar to Input and Output In C Language

UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
JavvajiVenkat
 
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
 
First c program
First c programFirst c program
First c program
Komal Pardeshi
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.com
Akanchha Agrawal
 
C programming
C programmingC programming
C programming
Shahariar limon
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
G. H. Raisoni Academy of Engineering & Technology, Nagpur
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
RohitRaj744272
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
SREEVIDYAP10
 
CHAPTER 4
CHAPTER 4CHAPTER 4
CHAPTER 4
mohd_mizan
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
Md. Ashikur Rahman
 
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
Thesis Scientist Private Limited
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
imtiazalijoono
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
trupti1976
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
educationfront
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
REHAN IJAZ
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
TechNGyan
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
Aditya Vaishampayan
 

Similar to Input and Output In C Language (20)

UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
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
 
First c program
First c programFirst c program
First c program
 
Basic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.comBasic of c programming www.eakanchha.com
Basic of c programming www.eakanchha.com
 
C programming
C programmingC programming
C programming
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
CHAPTER 4
CHAPTER 4CHAPTER 4
CHAPTER 4
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
 
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
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 

Recently uploaded

GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 

Recently uploaded (20)

GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 

Input and Output In C Language

  • 1. By: Prof. Adnan Faisal Khan
  • 2. By: Prof. Adnan Faisal Khan CHAPTER 10
  • 3. Standard Input • Standard input refers to the input using keyboard • A program may need certain input from the user • C language provides many functions to get intput from the user: • scanf() • gets() • getch() • getche() • Include the header file <stdio.h> in program to call scanf() and gets() and include the header file <conio.h> in program to call getch() and getche() function.
  • 4. Standard Output • The term standard output refers to the output displayed on the monitor • The result of a program is called the out of the program • C language provides many functions to display program output to the user • Printf() • Puts() • Include the header file <stdio.h> in program to call printf() and puts()
  • 5. printf ( ) function • The printf function is used to display output on the monitor • It can display text, constants, values of variables or expressions on monitor in specified format: Syntax: printf (Format String, argument_list); Format String Argument list • Also called control string • Give in double quotes • May consist of the following: • Text • Format specifiers • Escape sequence • Consists of constants, variable or expression are to be printed on the screen • Separated by comma • Use of argument list is optional
  • 6. • Using Format String without Argument List printf(“Hello World”); Control String • Using Format String with Single Argument int m =80; printf(“ Your marks are %d”, m); Control String • Using Format String with Multiple Arguments int m=80; char c=‘A’; • Printf(“your marks are %d and grade %c”, m, c); • One printf can print several lines by using newline escape sequence – ‘n’ printf( “ Welcome n to n C “); Format strings can have multiple format specifier, if you are printing multiple values
  • 7.
  • 8. Program 10.1 Write a program that displays a message and values of integer and character variables. #include<stdio.h> #include<conio.h> void main() { int n=10; char ch='*'; clrscr(); printf("Testing Output..."); printf("%d",n); printf("%c",ch); getch(); }
  • 9. Program 10.2 Write a program that adds two floating point numbers and shows the sum on the screen #include<stdio.h> #include<conio.h> void main() { float a=2.5,b=3.0,sum; sum = a+ b; clrscr(); printf(“%f + %f = %f ”,a,b,sum); getch(); }
  • 10. Program 10.3 Write a program that calculate and print area of square with given height and width #include<stdio.h> #include<conio.h> void main() { int area,h,w; h=2; w=4; area= h *w; printf(“Area of square is %d”,area); // printf(“ Area of square is %d when height is %d and width is %d”,area,h,w); getch(); }
  • 11. Format Specifier • Format specifier is used to specify the format according to which values will be read and display • It determines the following things: • Data type of Variable • Field width • Format of the value • Format specifier is started with symbol % • Different format specifiers are used with different types of variable • Integer format specifier • Character format specifier • Floating Point format specifier 3 4 5 1 3 4 5 1
  • 12. Format Specifier • Integer Format Specifier Format Specifier Type %d Used for signed decimal integer value %i Used for signed integer value %o Used for unsigned octal value %u Used for unsigned integer value %x Used for unsigned hexadecimal value with lower case like a,b,c etc. %X Used for unsigned hexadecimal value with Upper case like A,B,C etc.
  • 13. Format Specifier (Cont..) • Floating-Point Format Specifier • Character Format Specifier Format Specifier Type %f Used for signed floating point value %e Used for exponent value %g Used for short notation value Format Specifier Type %c Used for character value %s Used for strings
  • 14. How integer values are printed in C language? • The format specifier %d is used to display integer values in printf functions. • If an integer variable m contains 100 value then it can print by following statement: printf(“Your marks are %d”, m); output: Your marks are 100
  • 15. How floating point values are printed in C language? • The format specifier %f is used to display floating point value in printf function. • If an value of float variable a is 90.55 . The following statement: printf(“Average marks are %f”, a); output: Average marks are 90.550000
  • 17. Field Width specifier for integer • %d format specifier is used to display integer value in printf function • A value can be written between % and d in “%d” format specified Example int area =25; printf(“Area = %4d”,area); • The value will appear right-justified and two spaces will appear before the actual value
  • 18. Specifying width and precision for floating point value
  • 19.
  • 20. Programs From 10.4 to 10.8 from book
  • 21. Escape Sequence • Special characters used in format string to modify the format of output • Character are not displayed in the output • Always begin with backslash “”. • Backslash is called an escape character
  • 22. Escape sequence Character represented b Backspace f Form Feed n New Line r Carriage return t Tab ’ Single quote ” Double quote xdd ASCII code in hexadecimal notation. Each d represent digit ddd ASCII code in octal notation. Each d represents a digit
  • 23. • b use to insert backspace in the output • f (Form Feed page break) • n (New line) – We use it to shift the cursor control to the new line printf( • r (Carriage Return) – We use it to position the cursor to the beginning of the current line. • t (Horizontal tab) – We use it to shift the cursor to a couple of spaces to the right in the same line. • ’ (Apostrophe or single quotation mark) – We use it to display the single-quotation mark. • ” (Double quotation mark) – We use it to display the double- quotation mark. • (Backslash) – We use it to display the backslash character. • a (Audible bell) – A beep is generated indicating the execution of the program to alert the user.
  • 24. Programs From 10.9 to 10.11 from book
  • 25. Scanf Function • Read data from the standard input device ( Usually Keyboard) and store it in a variable • Requires stdio.h header file used to read input from keyboard • Syntax • scanf(“format string”, &variable);
  • 26.
  • 27. Programs From 10.12 to 10.22 from book
  • 28. Character Input • Scanf function can be used for character input • Scanf function is not suitable for all situations, specially when enter key is not require on any input ( e.g. arrow keys in games) • Specialized function for character input are available • getch() • getche() • These functions are part of conio.h library file
  • 29. getch() • The getch function is used to input single character from the user • Requires conio.h header file to use this function • When this function is executed, it waits for any key to be pressed • Character entered by the user is not displayed on the screen • The function is frequently used to pause program execution Syntax: [var =] getch(); Variable It indicates the variable in which the character is stored. The use of variable is optional
  • 30. Program 10.23 #include<stdio.h> #include<conio.h> Void main() { char c; clrscr(); printf(“ Enter Character ”); c= getch(); printf(“n You Entered %c”,c); getch(); } Enter Character You Entered s Output
  • 31. getche() • The getche() function is used to input single character from the user • Requires conio.h header file to use this function • When this function is executed, it waits for any key to be pressed • Character entered by the user displayed on the screen Syntax: [var =] getche(); Variable It indicates the variable in which the character is stored. The use of variable is optional
  • 32. Program 10.24 #include<stdio.h> #include<conio.h> Void main() { char c; clrscr(); printf(“ Enter Character ”); c= getche(); printf(“n You Entered %c”,c); getch(); } Enter Character s You Entered s Output
  • 33. gets() Function • Used to input string value from the user. • User press Enter key and string is stored variable • The null character is automatically entered at the end of string • Requires stdio.h header file to use this function Syntax: gets( String_Variable ); Example printf(“Enter a string”); gets(str); Suppose if user input “Pakistan” then the string will stores in str as follows: P a k i s t a n 0
  • 34. puts() Function • Used to display string on the screen. • It can display a string constant or string variable • Requires stdio.h header file to use this function Syntax: puts( parameter ); Parameter It indicates the string variable in which the string is stored. In case of string constant, it is written in double quotes Example puts(str);
  • 35. • Program 10.25 Write a program that inputs a string and displays it on a screen #include<stdio.h> #include<conio.h> void main() { char book[ 50]; clrscr(); printf(“Enter name of your favorit book”); gets(book); printf(“Your favorite book is”); puts(book); getch(); } Enter name of your favourite book : Holy Quran Your favourite book is : Holy Quran
  • 36. clrscr() Function • Used to clear screen • after clear the screen cursor blinks on the top-left corner • Requires conio.h header file to use this function Syntax: clrscr();
  • 37. sizeof Operator • Used to find the size of any data value • Its give the number of bytes occupied by that value Syntax: sizeof(operand); Examples : sizeof(10); sizeof(4.5); sizeof(“Pakistan”); sizeof(‘A’);