SlideShare a Scribd company logo
BUILDING SIMPLE C PROGRAM
ED 714: COMPUTER PROGRAMMING AND SYSTEM DESIGN
SESSION 3
JERALD P. CEJAS
Content Sharer
OPENING PRAYER
OPENING PRAYER
CLOSING PRAYER
CLOSING PRAYER
I. OBJECTIVES
I. OBJECTIVES
 Define input and output in C;
 Encode and run simple sample of
input/output programs;
 Build simple C program
II. DOCUMENTATION
II. DOCUMENTATION
 https://www.scaler.com/topics/c/input-and-output-
functions-in-c/
 https://www.programiz.com/c-programming/c-input-
output
 https://study.com/academy/lesson/basic-input-
output-in-c-programming.html
III. CONTENT OUTLINE
III. CONTENT OUTLINE
Building Simple C Program
 Input/Output
 Sample Programs
 Programming Exercises
INTRODUCTION
IV. THE REPORT
4.1 INTRODUCTION
What will be your answer if I ask you what is an algorithm?
Then you may reply that it is a step-by-step procedure over a set of
instructions that provide us with the desired Output. Then my cross-
question will be, "Desired Output for what?" Again it is easy, “Output for an
Input”. So this means most of the algorithms/programs take an Input to
perform a step-by-step procedure to provide the desired Output.
Input is given through the keyboard, and output may be shown
on screen or printed through the printer or in another way. Still, for the
different devices, there may be a different type of process for input/output,
which may be a problem for the programmer. To avoid this, all input/output
are done using streams in C, which handles input/output without taking care
of where input is coming and the destination of the output. It can be added
to any C program by introducing a Standard Input/Output library using
stdio.h header.
Stream is the sequence of bytes of data in the form of a
sequence of characters. While taking input, we get a sequence of
characters entering into our program, that is, the input stream and for
output, we send a sequence of characters out from our program, which is
the output stream. The main advantage of the stream is it makes
input/output programming independent of the device.
What is input in C?
Have you visited ATMs? If yes, you know ATM is an Electronic Banking
outlet that provides transactions to the users based on some set of instructions.
Still, for every user, it requires some details like a PIN, which means most
algorithms have some set of instructions but need some external data/information
to work over it. Input refers to the process of feeding data into the program. Data
can be in a command line or from a file. Random Access Memory is kept by the C
program while executing. When data come from an external location to the
program, it is moved to RAM where the program can access it and that external
data is known as input.
INPUT/ OUTPUT IN C
What is input in C?
What is output
in C?
Let's continue our ATM story so that when users provide PINs and other required
inputs, the ATM, after performing all the instructions, provides cash, bank details, or other
desired stuff, which means the algorithm, after performing on the input, provides the
desired results. Still, it may be in different ways, like the output on screen or a print
through a printer or in another way. Output refers to sending data out of the program or
simply sending data to the location out of the program memory. The destination of the
data may be a screen, printer, or Disk. For getting output, it is not always compulsory to
have an input, like an algorithm for generating random numbers will simply return random
numbers without any input.
INPUT/ OUTPUT IN C
What is output in C?
How to take input &
output of basic types
in C?
We have some input and output functions in C, let's look over them:
INPUT
For taking input in C, we use the built-in function of the C scanf(). scanf() method
reads the input from standard input stream stdin and scans that input as per the
type specified.
Syntax of taking input in C
How to take input and output of basic types in C?
Syntax of taking input in C
The above syntax is for taking input from the user. Where %A defines format
specifier in C, it helps the compiler identify the data type of variable for which we
will take input, and '&' is the address operator in C. It helps the compiler change
the actual value of this variable stored at this address in the memory.
We have some input and output functions in C, let's look over them:
OUTPUT
For display output to the user in C, we are using the built-in function of C printf().
printf() method writes the output to the standard output stream stdout and prints
the value passed as the parameter to it.
Syntax of taking output in C
How to take input and output of basic types in C?
Syntax of taking output in C
The above syntax for displays output to the user. Where %A defines format
specifier in C, it helps the compiler identify the data type of variable we are going
to output.
The basic type of input and output in C includes data types of variables like int,
float, char, etc. The A in the above syntax is replaced with the appropriate format
specifier of that type
Format specifier for different data types
Data Type value of A
int %d
float %f
char %c
long %l or %ld
double %lf
Syntax of input and output of basic data types in C
Example
Output
The above code takes the inputs for
variables of a type character, integer,
and float using scanf and then outputs
them using printf() with the help of
proper format specifiers.
SAMPLE
PROGRAM
SAMPLE PROGRAM
Example 1: Integer Input/Output
Output
Enter an integer: 4
Number = 4
Here, we have used %d format
specifier inside the scanf()
function to take int input from the
user. When the user enters an
integer, it is stored in the testInteger
variable.
SAMPLE PROGRAM
Example 2: Float and Double Input/Output
Output
Enter a number: 12.523
Enter another number: 10.2
num1 = 12.523000
num2 = 10.200000
SAMPLE PROGRAM
Example 3: C Character Input/Output
Output
Enter a character = g
You entered g
SAMPLE PROGRAM
Example 4: https://www.youtube.com/watch?v=hgYnQW5znjE
SAMPLE PROGRAM
Example 5: https://www.youtube.com/watch?v=17gp5DJEyiw&list=PL98qAXLA
6aftD9ZlnjpLhdQAOFI8xIB6e
PROGRAMMING
EXERCISES
PROGRAMMING EXERCISES
Exercise 1: Write a program in C that calculate the sum of three numbers with
getting input in one line separated by a comma.
#include <stdio.h>
int main()
{
int a,b,c,d;
printf("Please enter any three numbers separated by a comma:");
scanf("%d, %d, %d", &a, &b, &c);
d = a + b + c;
printf("The sum of three number is: %d", d);
return 0;
}
PROGRAMMING EXERCISES
Exercise 2: Write a C program to perform addition, subtraction, multiplication and
division of two numbers.
#include <stdio.h>
int main()
{
int a,b,c,d,e,f;
printf("Please enter any two numbers separated by a comma:");
scanf("%d, %d,", &a, &b);
c = a + b;
d = a - b;
e = a * b;
f = a / b;
printf("The sum of two numbers is: %dn", c);
printf("The difference of two numbers is: %dn",d);
printf("The product of two number is: %dn", e);
printf("The quotient of two number is: %dn", f);
return 0;
}
PROGRAMMING EXERCISES
Exercise 3: Write a C program that prints the perimeter and area of a rectangle to
take its height and width as input.
jerald.cejas@ctu.edu.ph
Zig Ziglar

More Related Content

Similar to Building Simple C Program

UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
JavvajiVenkat
 
C programming
C programmingC programming
C programming
PralhadKhanal1
 
COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
RSathyaPriyaCSEKIOT
 
Unit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptxUnit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptx
PragatheshP
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
Programming in c
Programming in cProgramming in c
Programming in c
Ashutosh Srivasatava
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
Sivakumar R D .
 
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 language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
AashutoshChhedavi
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
LidetAdmassu
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
complete data structure
complete data structurecomplete data structure
complete data structure
Anuj Arora
 
Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01Getachew Ganfur
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners
ShreyaSingh291866
 
C language
C language C language
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
 

Similar to Building Simple C Program (20)

UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
C programming
C programmingC programming
C programming
 
COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
 
Unit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptxUnit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptx
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
 
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 language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
 
Chapter3
Chapter3Chapter3
Chapter3
 
complete data structure
complete data structurecomplete data structure
complete data structure
 
Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01Datastructurenotes 100627004340-phpapp01
Datastructurenotes 100627004340-phpapp01
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners
 
C language
C language C language
C language
 
Intro
IntroIntro
Intro
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 

Recently uploaded

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
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
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
 
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 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
 
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
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
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.
 
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
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 

Recently uploaded (20)

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
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
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
 
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 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
 
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
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
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
 
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
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 

Building Simple C Program

  • 1. BUILDING SIMPLE C PROGRAM ED 714: COMPUTER PROGRAMMING AND SYSTEM DESIGN SESSION 3 JERALD P. CEJAS Content Sharer
  • 7. I. OBJECTIVES  Define input and output in C;  Encode and run simple sample of input/output programs;  Build simple C program
  • 9. II. DOCUMENTATION  https://www.scaler.com/topics/c/input-and-output- functions-in-c/  https://www.programiz.com/c-programming/c-input- output  https://study.com/academy/lesson/basic-input- output-in-c-programming.html
  • 11. III. CONTENT OUTLINE Building Simple C Program  Input/Output  Sample Programs  Programming Exercises
  • 13. IV. THE REPORT 4.1 INTRODUCTION What will be your answer if I ask you what is an algorithm? Then you may reply that it is a step-by-step procedure over a set of instructions that provide us with the desired Output. Then my cross- question will be, "Desired Output for what?" Again it is easy, “Output for an Input”. So this means most of the algorithms/programs take an Input to perform a step-by-step procedure to provide the desired Output.
  • 14. Input is given through the keyboard, and output may be shown on screen or printed through the printer or in another way. Still, for the different devices, there may be a different type of process for input/output, which may be a problem for the programmer. To avoid this, all input/output are done using streams in C, which handles input/output without taking care of where input is coming and the destination of the output. It can be added to any C program by introducing a Standard Input/Output library using stdio.h header.
  • 15. Stream is the sequence of bytes of data in the form of a sequence of characters. While taking input, we get a sequence of characters entering into our program, that is, the input stream and for output, we send a sequence of characters out from our program, which is the output stream. The main advantage of the stream is it makes input/output programming independent of the device.
  • 16. What is input in C?
  • 17. Have you visited ATMs? If yes, you know ATM is an Electronic Banking outlet that provides transactions to the users based on some set of instructions. Still, for every user, it requires some details like a PIN, which means most algorithms have some set of instructions but need some external data/information to work over it. Input refers to the process of feeding data into the program. Data can be in a command line or from a file. Random Access Memory is kept by the C program while executing. When data come from an external location to the program, it is moved to RAM where the program can access it and that external data is known as input. INPUT/ OUTPUT IN C What is input in C?
  • 19. Let's continue our ATM story so that when users provide PINs and other required inputs, the ATM, after performing all the instructions, provides cash, bank details, or other desired stuff, which means the algorithm, after performing on the input, provides the desired results. Still, it may be in different ways, like the output on screen or a print through a printer or in another way. Output refers to sending data out of the program or simply sending data to the location out of the program memory. The destination of the data may be a screen, printer, or Disk. For getting output, it is not always compulsory to have an input, like an algorithm for generating random numbers will simply return random numbers without any input. INPUT/ OUTPUT IN C What is output in C?
  • 20. How to take input & output of basic types in C?
  • 21. We have some input and output functions in C, let's look over them: INPUT For taking input in C, we use the built-in function of the C scanf(). scanf() method reads the input from standard input stream stdin and scans that input as per the type specified. Syntax of taking input in C How to take input and output of basic types in C?
  • 22. Syntax of taking input in C The above syntax is for taking input from the user. Where %A defines format specifier in C, it helps the compiler identify the data type of variable for which we will take input, and '&' is the address operator in C. It helps the compiler change the actual value of this variable stored at this address in the memory.
  • 23. We have some input and output functions in C, let's look over them: OUTPUT For display output to the user in C, we are using the built-in function of C printf(). printf() method writes the output to the standard output stream stdout and prints the value passed as the parameter to it. Syntax of taking output in C How to take input and output of basic types in C?
  • 24. Syntax of taking output in C The above syntax for displays output to the user. Where %A defines format specifier in C, it helps the compiler identify the data type of variable we are going to output. The basic type of input and output in C includes data types of variables like int, float, char, etc. The A in the above syntax is replaced with the appropriate format specifier of that type
  • 25. Format specifier for different data types Data Type value of A int %d float %f char %c long %l or %ld double %lf
  • 26. Syntax of input and output of basic data types in C
  • 27. Example Output The above code takes the inputs for variables of a type character, integer, and float using scanf and then outputs them using printf() with the help of proper format specifiers.
  • 29. SAMPLE PROGRAM Example 1: Integer Input/Output Output Enter an integer: 4 Number = 4 Here, we have used %d format specifier inside the scanf() function to take int input from the user. When the user enters an integer, it is stored in the testInteger variable.
  • 30. SAMPLE PROGRAM Example 2: Float and Double Input/Output Output Enter a number: 12.523 Enter another number: 10.2 num1 = 12.523000 num2 = 10.200000
  • 31. SAMPLE PROGRAM Example 3: C Character Input/Output Output Enter a character = g You entered g
  • 32. SAMPLE PROGRAM Example 4: https://www.youtube.com/watch?v=hgYnQW5znjE
  • 33. SAMPLE PROGRAM Example 5: https://www.youtube.com/watch?v=17gp5DJEyiw&list=PL98qAXLA 6aftD9ZlnjpLhdQAOFI8xIB6e
  • 35. PROGRAMMING EXERCISES Exercise 1: Write a program in C that calculate the sum of three numbers with getting input in one line separated by a comma. #include <stdio.h> int main() { int a,b,c,d; printf("Please enter any three numbers separated by a comma:"); scanf("%d, %d, %d", &a, &b, &c); d = a + b + c; printf("The sum of three number is: %d", d); return 0; }
  • 36. PROGRAMMING EXERCISES Exercise 2: Write a C program to perform addition, subtraction, multiplication and division of two numbers. #include <stdio.h> int main() { int a,b,c,d,e,f; printf("Please enter any two numbers separated by a comma:"); scanf("%d, %d,", &a, &b); c = a + b; d = a - b; e = a * b; f = a / b; printf("The sum of two numbers is: %dn", c); printf("The difference of two numbers is: %dn",d); printf("The product of two number is: %dn", e); printf("The quotient of two number is: %dn", f); return 0; }
  • 37. PROGRAMMING EXERCISES Exercise 3: Write a C program that prints the perimeter and area of a rectangle to take its height and width as input.