SlideShare a Scribd company logo
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 1
Handout#2
Assignment/Program Statement:
Study basic structure of C program and write C programs using formatted input-
output functions, clrscr() function and getch() function in C.
Learning Objectives:
Students will be able to
- explain basic structure of C program
- explain printf, scanf, clrsrc() and getch() functions in C
- write C code using formatted input functions in C (i.e. scanf)
- write C code using formatted output functions in C (i.e. printf)
Theory:
[I] Basic Structure of C Program
Documentation Section
 This section consists of comment lines which include the name of
programmer, the author and other details like time and date of writing the
program.
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 2
 Documentation section helps anyone to get an overview of the program.
Link Section
 The link section consists of the header files of the functions that are used in
the program.
 It provides instructions to the compiler to link functions from the system
library.
Definition Section
 All the symbolic constants are written in definition section.
 Macros are known as symbolic constants.
Global Declaration Section
 The global variables that can be used anywhere in the program are declared
in global declaration section.
 This section also declares the user defined functions.
main() Function Section
 It is necessary have one main() function section in every C program.
 This section contains two parts, declaration and executable part.
 The declaration part declares all the variables that are used in executable
part.
 These two parts must be written in between the opening and closing braces.
 Each statement in the declaration and executable part must end with a
semicolon (;).
 The execution of program starts at opening braces and ends at closing
braces.
Subprogram Section
 The subprogram section contains all the user defined functions that are used
to perform a specific task.
 These user defined functions are called in the main() function.
[Reference: http://www.thecrazyprogrammer.com/2013/07/explain-basic-structure-of-c-
programs.html ]
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 3
Sample C Program:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(“Hello World”);
getch();
}
[II] Basics of Formatted Input/Output in C
(A) Output with printf
 The basic format of a printf function call is:
printf (format_string, list_of_expressions);
where:
 format_string is the layout of what's being printed
 list_of_expressions is a comma-separated list of variables or expressions
yielding results to be inserted into the output
To output string literals, just use one parameter on printf, the string itself
printf("Hello, world!n");
printf("Greetings, Earthlingnn");
Sample C Program:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf(“Hello World”);
getch();
}
Header files required to use
built-in functions in C
main() function in C-program
C-function to clear screen
C-function to print
statement on screen
C-function to read a
key from keyboard
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 4
Conversion Specifiers:
A conversion specifier is a symbol that is used as a placeholder in a formatting
string. For integer output (for example), %d is the specifier that holds the place for
integers.
Here are some commonly used conversion specifiers (not a comprehensive list):
%d int (signed decimal integer)
%u unsigned decimal integer
%f floating point values (fixed notation) - float, double
%e floating point values (exponential notation)
%s string
%c character
 To output an integer, use %d in the format string, and an integer expression
in the list of expressions.
int totalStuds = 523;
printf("First Year of Engineering has %d students", totalStuds);
 Use the %f modifer to print floating point values in fixed notation:
double cost = 123.45;
printf("Your total is $%f todayn", cost);
(B) Input with scanf
 To read data in from standard input (keyboard), we call the scanf function.
 The basic format of a scanf function call is:
scanf(format_string, list_of_variable_addresses);
where:
 format_string is the layout of what's being read
 list_ of_variable_addresses is a comma-separated list of addresses variables
which specify space to store incoming data
 If x is a variable, then the expression &x means "address of x"
Example: int month, day;
printf("Please enter your birth month, followed by the day: ");
scanf("%d %d", &month, &day);
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 5
Conversion Specifiers
 Same as for output but with some small differences
 Use %f for type float, but use %lf for types double and long double
 The data type read, the conversion specifier, and the variable used need to
match in type.
 White space is skipped by default in consecutive numeric reads. But it is not
skipped for character/string inputs.
Example:
#include <stdio.h>
int main()
{
int i;
float f;
char c;
printf("Enter an integer and a float, then Y or Nn> ");
scanf("%d%f%c", &i, &f, &c);
printf("You entered:n");
printf("i = %d, f = %f, c = %cn", i, f, c);
}
(C) Interactive Input
 You can make input more interactive by prompting the user more carefully.
 This can be tedious in some places, but in many occasions, it makes
programs more user-friendly.
Example:
int rollNo, marks;
char answer;
printf("Please enter your Roll No: ");
scanf("%d", &rollNo);
printf("Please enter your marks: ");
scanf("%d",&marks);
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 6
printf("Do you want to continue (Y/N)? ");
scanf("%c",&answer);
[III] clrscr() function in C:
 It is built-in function in "conio.h" (console input output header file) used to
clear the console screen.
 It is used to clear the data from console (Monitor).
 Use of clrscr() function is always optional.
 This function should be place after variable or function declaration only.
[Reference: www.tutorial4us.com/cprogramming/c-clrscr-and-getch ]
[IV] getch() function in C:
 It is built-in function available under in "conio.h" (console input output
header file) will tell to the console wait for some time until a key is hit given
after running of program.
 This function can be used to read a character directly from the keyboard.
 Generally getch() are placing at end of the program after printing the output
on screen.
[Reference: www.tutorial4us.com/cprogramming/c-clrscr-and-getch ]
Example:
#include<stdio.h>
void main()
{
int rollNo, marks;
clrscr();
printf("Please enter your Roll No: ");
scanf("%d", &rollNo);
printf("Please enter your marks: ");
scanf("%d",&marks);
getch();
}
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 7
Practice Problem Statements:
[Note: In following programs make use of clrscr() and getch() functions]
1) Write a program demonstrating scanf() function for addition of two numbers.
2) Write a program to read five subjects (Maths, BECP, Chemistry, Basic Civil &
Engineering Graphics) marks and display the average, percentage & total marks in
the following format
----------------------------------------------------------------------------------------
INPUT: Entered Marks
Maths : 85
BECP : 90
Chemistry : 80
Basic Civil : 75
Engineering Graphics : 92
---------------------------------------------------------------------------------------
OUTPUT:
Total Marks : 422
Average : 84.4
Percentage : 84.4%
----------------------------------------------------------------------------------------
Conclusion:
Thus we have studies the basic structure of C program, basic functions in C such as
printf to print and scanf to read. To clear screen, clrsrc() in C and to read key input
from keyboard getch(), we studied.
Learning Outcomes:
At the end of this assignment, students are able to
- explain basic structure of C program
- explain printf, scanf, clrsrc() and getch() functions in C
- write C code using formatted input functions in C (i.e. scanf)
- write C code using formatted output functions in C (i.e. printf)

More Related Content

What's hot

CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
trupti1976
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
nTier Custom Solutions
 
C fundamentals
C fundamentalsC fundamentals
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
Vikram Nandini
 
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 .
 
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshop
neosphere
 
What is c
What is cWhat is c
What is c
Nitesh Saitwal
 
Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
Abir Hossain
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
sachindane
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
Rai University
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
Anil Bishnoi
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
Vikram Nandini
 
Casa lab manual
Casa lab manualCasa lab manual
Casa lab manual
BHARATNIKKAM
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming9
 
C programming
C programmingC programming
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
Syed Mustafa
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 

What's hot (20)

CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
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 Workshop
C programming WorkshopC programming Workshop
C programming Workshop
 
C Programming
C ProgrammingC Programming
C Programming
 
What is c
What is cWhat is c
What is c
 
Important C program of Balagurusamy Book
Important C program of Balagurusamy BookImportant C program of Balagurusamy Book
Important C program of Balagurusamy Book
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Programming with c language practical manual
Programming with c language practical manualProgramming with c language practical manual
Programming with c language practical manual
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Casa lab manual
Casa lab manualCasa lab manual
Casa lab manual
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
C programming
C programmingC programming
C programming
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 

Viewers also liked

Chapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and PolymorphismChapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and Polymorphism
Eduardo Bergavera
 
8.3 program structure (1 hour)
8.3 program structure (1 hour)8.3 program structure (1 hour)
8.3 program structure (1 hour)
akmalfahmi
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
Jyoti Bhardwaj
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments
rajni kaushal
 
Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]
Abdullah khawar
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
Eduardo Bergavera
 
Chapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramChapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramDeepak Singh
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
HNDE Labuduwa Galle
 
Loop c++
Loop c++Loop c++
Loop c++
Mood Mood
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
طارق بالحارث
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
Appili Vamsi Krishna
 
Array in c++
Array in c++Array in c++
Array in c++
Mahesha Mano
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 
Structure in c
Structure in cStructure in c
Structure in c
Prabhu Govind
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentationNeveen Reda
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
Anil Kumar
 
c++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ programc++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ program
AAKASH KUMAR
 

Viewers also liked (20)

Chapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and PolymorphismChapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and Polymorphism
 
8.3 program structure (1 hour)
8.3 program structure (1 hour)8.3 program structure (1 hour)
8.3 program structure (1 hour)
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments
 
Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]
 
Apclass
ApclassApclass
Apclass
 
Apclass (2)
Apclass (2)Apclass (2)
Apclass (2)
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
 
Chapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramChapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ Program
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
Loop c++
Loop c++Loop c++
Loop c++
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
 
Array in c++
Array in c++Array in c++
Array in c++
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
Structure in c
Structure in cStructure in c
Structure in c
 
Structure in c
Structure in cStructure in c
Structure in c
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
 
c++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ programc++ programming Unit 2 basic structure of a c++ program
c++ programming Unit 2 basic structure of a c++ program
 

Similar to CP Handout#2

Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
REHAN IJAZ
 
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
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
JavvajiVenkat
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
Unit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptxUnit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptx
PragatheshP
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
TechNGyan
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
Mehul Desai
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
SURBHI SAROHA
 
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
 
COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
C structure
C structureC structure
C structure
ankush9927
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
educationfront
 
C programming course material
C programming course materialC programming course material
C programming course material
Ranjitha Murthy
 
1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx
tarifarmarie
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
Bhavik Vashi
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
TejaswiB4
 

Similar to CP Handout#2 (20)

Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
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
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Chapter3
Chapter3Chapter3
Chapter3
 
Unit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptxUnit 2 CMath behind coding.pptx
Unit 2 CMath behind coding.pptx
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Introduction to C Unit 1
Introduction to C Unit 1Introduction to C Unit 1
Introduction to C Unit 1
 
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
 
COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
 
C structure
C structureC structure
C structure
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
 
C programming
C programmingC programming
C programming
 
C programming course material
C programming course materialC programming course material
C programming course material
 
1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx1 CMPS 12M Introduction to Data Structures Lab La.docx
1 CMPS 12M Introduction to Data Structures Lab La.docx
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 

More from trupti1976

MobileAppDev Handout#3
MobileAppDev Handout#3MobileAppDev Handout#3
MobileAppDev Handout#3
trupti1976
 
MobileAppDev Handout#10
MobileAppDev Handout#10MobileAppDev Handout#10
MobileAppDev Handout#10
trupti1976
 
MobileAppDev Handout#9
MobileAppDev Handout#9MobileAppDev Handout#9
MobileAppDev Handout#9
trupti1976
 
MobileAppDev Handout#8
MobileAppDev Handout#8MobileAppDev Handout#8
MobileAppDev Handout#8
trupti1976
 
MobileAppDev Handout#7
MobileAppDev Handout#7MobileAppDev Handout#7
MobileAppDev Handout#7
trupti1976
 
MobileAppDev Handout#6
MobileAppDev Handout#6MobileAppDev Handout#6
MobileAppDev Handout#6
trupti1976
 
MobileAppDev Handout#5
MobileAppDev Handout#5MobileAppDev Handout#5
MobileAppDev Handout#5
trupti1976
 
MobileAppDev Handout#4
MobileAppDev Handout#4MobileAppDev Handout#4
MobileAppDev Handout#4
trupti1976
 
MobileAppDev Handout#2
MobileAppDev Handout#2MobileAppDev Handout#2
MobileAppDev Handout#2
trupti1976
 
MobileAppDev Handout#1
MobileAppDev Handout#1MobileAppDev Handout#1
MobileAppDev Handout#1
trupti1976
 

More from trupti1976 (10)

MobileAppDev Handout#3
MobileAppDev Handout#3MobileAppDev Handout#3
MobileAppDev Handout#3
 
MobileAppDev Handout#10
MobileAppDev Handout#10MobileAppDev Handout#10
MobileAppDev Handout#10
 
MobileAppDev Handout#9
MobileAppDev Handout#9MobileAppDev Handout#9
MobileAppDev Handout#9
 
MobileAppDev Handout#8
MobileAppDev Handout#8MobileAppDev Handout#8
MobileAppDev Handout#8
 
MobileAppDev Handout#7
MobileAppDev Handout#7MobileAppDev Handout#7
MobileAppDev Handout#7
 
MobileAppDev Handout#6
MobileAppDev Handout#6MobileAppDev Handout#6
MobileAppDev Handout#6
 
MobileAppDev Handout#5
MobileAppDev Handout#5MobileAppDev Handout#5
MobileAppDev Handout#5
 
MobileAppDev Handout#4
MobileAppDev Handout#4MobileAppDev Handout#4
MobileAppDev Handout#4
 
MobileAppDev Handout#2
MobileAppDev Handout#2MobileAppDev Handout#2
MobileAppDev Handout#2
 
MobileAppDev Handout#1
MobileAppDev Handout#1MobileAppDev Handout#1
MobileAppDev Handout#1
 

Recently uploaded

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
DuvanRamosGarzon1
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 

Recently uploaded (20)

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSETECHNICAL TRAINING MANUAL   GENERAL FAMILIARIZATION COURSE
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSE
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 

CP Handout#2

  • 1. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 1 Handout#2 Assignment/Program Statement: Study basic structure of C program and write C programs using formatted input- output functions, clrscr() function and getch() function in C. Learning Objectives: Students will be able to - explain basic structure of C program - explain printf, scanf, clrsrc() and getch() functions in C - write C code using formatted input functions in C (i.e. scanf) - write C code using formatted output functions in C (i.e. printf) Theory: [I] Basic Structure of C Program Documentation Section  This section consists of comment lines which include the name of programmer, the author and other details like time and date of writing the program.
  • 2. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 2  Documentation section helps anyone to get an overview of the program. Link Section  The link section consists of the header files of the functions that are used in the program.  It provides instructions to the compiler to link functions from the system library. Definition Section  All the symbolic constants are written in definition section.  Macros are known as symbolic constants. Global Declaration Section  The global variables that can be used anywhere in the program are declared in global declaration section.  This section also declares the user defined functions. main() Function Section  It is necessary have one main() function section in every C program.  This section contains two parts, declaration and executable part.  The declaration part declares all the variables that are used in executable part.  These two parts must be written in between the opening and closing braces.  Each statement in the declaration and executable part must end with a semicolon (;).  The execution of program starts at opening braces and ends at closing braces. Subprogram Section  The subprogram section contains all the user defined functions that are used to perform a specific task.  These user defined functions are called in the main() function. [Reference: http://www.thecrazyprogrammer.com/2013/07/explain-basic-structure-of-c- programs.html ]
  • 3. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 3 Sample C Program: #include<stdio.h> #include<conio.h> void main() { clrscr(); printf(“Hello World”); getch(); } [II] Basics of Formatted Input/Output in C (A) Output with printf  The basic format of a printf function call is: printf (format_string, list_of_expressions); where:  format_string is the layout of what's being printed  list_of_expressions is a comma-separated list of variables or expressions yielding results to be inserted into the output To output string literals, just use one parameter on printf, the string itself printf("Hello, world!n"); printf("Greetings, Earthlingnn"); Sample C Program: #include<stdio.h> #include<conio.h> void main() { clrscr(); printf(“Hello World”); getch(); } Header files required to use built-in functions in C main() function in C-program C-function to clear screen C-function to print statement on screen C-function to read a key from keyboard
  • 4. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 4 Conversion Specifiers: A conversion specifier is a symbol that is used as a placeholder in a formatting string. For integer output (for example), %d is the specifier that holds the place for integers. Here are some commonly used conversion specifiers (not a comprehensive list): %d int (signed decimal integer) %u unsigned decimal integer %f floating point values (fixed notation) - float, double %e floating point values (exponential notation) %s string %c character  To output an integer, use %d in the format string, and an integer expression in the list of expressions. int totalStuds = 523; printf("First Year of Engineering has %d students", totalStuds);  Use the %f modifer to print floating point values in fixed notation: double cost = 123.45; printf("Your total is $%f todayn", cost); (B) Input with scanf  To read data in from standard input (keyboard), we call the scanf function.  The basic format of a scanf function call is: scanf(format_string, list_of_variable_addresses); where:  format_string is the layout of what's being read  list_ of_variable_addresses is a comma-separated list of addresses variables which specify space to store incoming data  If x is a variable, then the expression &x means "address of x" Example: int month, day; printf("Please enter your birth month, followed by the day: "); scanf("%d %d", &month, &day);
  • 5. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 5 Conversion Specifiers  Same as for output but with some small differences  Use %f for type float, but use %lf for types double and long double  The data type read, the conversion specifier, and the variable used need to match in type.  White space is skipped by default in consecutive numeric reads. But it is not skipped for character/string inputs. Example: #include <stdio.h> int main() { int i; float f; char c; printf("Enter an integer and a float, then Y or Nn> "); scanf("%d%f%c", &i, &f, &c); printf("You entered:n"); printf("i = %d, f = %f, c = %cn", i, f, c); } (C) Interactive Input  You can make input more interactive by prompting the user more carefully.  This can be tedious in some places, but in many occasions, it makes programs more user-friendly. Example: int rollNo, marks; char answer; printf("Please enter your Roll No: "); scanf("%d", &rollNo); printf("Please enter your marks: "); scanf("%d",&marks);
  • 6. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 6 printf("Do you want to continue (Y/N)? "); scanf("%c",&answer); [III] clrscr() function in C:  It is built-in function in "conio.h" (console input output header file) used to clear the console screen.  It is used to clear the data from console (Monitor).  Use of clrscr() function is always optional.  This function should be place after variable or function declaration only. [Reference: www.tutorial4us.com/cprogramming/c-clrscr-and-getch ] [IV] getch() function in C:  It is built-in function available under in "conio.h" (console input output header file) will tell to the console wait for some time until a key is hit given after running of program.  This function can be used to read a character directly from the keyboard.  Generally getch() are placing at end of the program after printing the output on screen. [Reference: www.tutorial4us.com/cprogramming/c-clrscr-and-getch ] Example: #include<stdio.h> void main() { int rollNo, marks; clrscr(); printf("Please enter your Roll No: "); scanf("%d", &rollNo); printf("Please enter your marks: "); scanf("%d",&marks); getch(); }
  • 7. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 7 Practice Problem Statements: [Note: In following programs make use of clrscr() and getch() functions] 1) Write a program demonstrating scanf() function for addition of two numbers. 2) Write a program to read five subjects (Maths, BECP, Chemistry, Basic Civil & Engineering Graphics) marks and display the average, percentage & total marks in the following format ---------------------------------------------------------------------------------------- INPUT: Entered Marks Maths : 85 BECP : 90 Chemistry : 80 Basic Civil : 75 Engineering Graphics : 92 --------------------------------------------------------------------------------------- OUTPUT: Total Marks : 422 Average : 84.4 Percentage : 84.4% ---------------------------------------------------------------------------------------- Conclusion: Thus we have studies the basic structure of C program, basic functions in C such as printf to print and scanf to read. To clear screen, clrsrc() in C and to read key input from keyboard getch(), we studied. Learning Outcomes: At the end of this assignment, students are able to - explain basic structure of C program - explain printf, scanf, clrsrc() and getch() functions in C - write C code using formatted input functions in C (i.e. scanf) - write C code using formatted output functions in C (i.e. printf)