SlideShare a Scribd company logo
1 of 61
Programming in C
Lecture 01
By-
Jesmin Akhter
Associate Professor, IIT, Jahangirnagar University
TEXT BOOK
Programming in ANCI ‘C
By: E Balagurusamy. TMH
Chapter 01
Importance of C
• C is the base language of any other programming language.
• To be a Good Programmer one must know fundamentals of C
programming language.
• It is a robust language.
• Whose rich set of built in functions and operators can be used to write any complex
program.
• Programs written in ‘C’ are efficient and fast.
• Because of variety of data types and powerful operators
• Highly Portable. (related to OS)
– C program written for one computer can be run on another with little or no
modification
• Well suited for structured programming
• Ability to extend itself
• Well suited for writing system software
– UNIX, MS-DOS operating system,
Program & Programming Language
• Program:- A Set of instructions which carried out
by processor for some Specific input, generates
specific output.
• Programming language:- A specific manner of
writing a program with some Predefined rules,
symbols & their use as a part of language.
– i.e. Pascal, C, C++, VC++, JAVA, VB.
Basic structure of ‘C’
1) Documentation Section :-
It has set of comment lines(name of program, author
details).
What is Comment line??
 To guide a programmer. To write a note for
function,operation,logic in between a program.
 Non-executable statement.
 Can’t be nested.
e.g:- /* Hello /* abc */ Hi */
ERROR.
2)Link Section :-
It provides instructions to the compiler to
link
function from the system library.
# include Directive:-
 To access the functions which are stored in
the
library, it is necessary to tell the compiler ,
about the file to be accessed.
Syntax:-
#include<stdio.h>
 stdio.h is header file.
3) Definition Section
It defines all symbolic constants.
#define instruction defines value to a symbolic
constant.
#define:-
It is a preprocessor compiler directive, not a
statement.
Therefore it should not end with a semicolon.
Generally written in uppercase.
4)Global Declaration Section
Some variables that are used in more than
one function, such variables (global variables)
declared in the global declaration section.
It also declares all the user-defined function.
5) Main() function section:
Every ‘C’ program must have one main() function
section.
It contains two parts
1) Declaration part:
It declares all variables used in the executable part.
2) Executable part:
It has atleast one statement.
Ex: main( ) = main (void)
No arguments Explicitly indicate no arguments
5) Basic structure of C Programs:
Documentation section
Link Section
Definition Section
Global Declaration Section
main() function section
{
Declaration part
Executable part
}
Subprogram section
Function1
Function2
…
user defined function
How to run a program?
• There are two ways to run programs written
in a high-level language.
– The most common is to compile the program
– The other method is to pass the program through
an interpreter.
Why Compiler
• As machine (a processor) can operate on binary
code instruction only…..
• If we use higher level language then …
– For execution of the program we must convert it to
lower level / machine level code.
• Compiler is a program that translates source code
into object code.
• The compiler derives its name from the way it
works, looking at the entire piece of source code
and collecting and reorganizing the instructions.
Interpreter
• Analyzes and executes each line of source code
without looking at the entire program.
Advantage of interpreter:
• It can execute a program immediately.
– Compilers require some time before an executable
program emerges.
• But,
– However, programs produced by compilers run much
faster than the same programs executed by an
interpreter.
C Compiler
- checks for syntax errors if any
- on success coverts ‘C source code
into object code form –
which is nearer to machine…
Linker:
A linker is a program that combines object
modules to form an executable program.
Types of languages
(I)Lower level languages:-
Languages which are very near to
machine…. I.e. machine language,
Assembly language.
(II) Higher level languages:-
Languages which are very near to
programmer rather than to machine….
I.e. C++,Visual C++,Visual basic,Java.
BlockDiagram:
Represents only
-> what should be the input?
-> what will be the output?
- One need not to worry about how
the result generated….
- or what will be the logic for the
program?
Input
No1. &
No2. PROGRAM No1 + No2
Output
Block Diagram for making addition of two
numbers
Algorithm
Specifies steps of doing the things
Irrespective of any programming language
Example: Addition of two numbers
Step 1: [Read two numbers]
Read(no1)
Read(no2)
Step 2:[add two numbers into sum]
summation = no1 + no2
Step 3:[Display the result]
write (summation)
Flowchart
Represents the flow of program
Symbols:-
Start-Begin/End
Input/Output Rectangle
Process box/operation box
Decision Box
Connector
Flowchart-example
Example: To add two numbers and display the
result.
Start
SUMMATION = NO1 + NO2
End
Read No1 and No2 from user
Write Summation on monitor
Files ,directory, file extension
Files:- storage of logically related data
Directory:- Placeholder which can store files
and subdirectories within them.
File Extension:- special postfix attached to
each file which indicates type
of the file.
Sample C program:-
/* print hello*/
#include<stdio.h> /* link section*/
void main() /* execution of program*/
{
print(“hello world”); /*executable
statement*/
}
Chapter 02
C AS A LANGUAGE
• Interface between computer & human
being.
ALPHABETS WORDS SENTENCES PARAGRAPH
Alphabets, digits
special symbol
Constants,
Variables,
Keywords
Instructions Program
C CHARACTER SET
 ALPHABETS A,B…………Z
a,b………….z
 DIGITS 0,1,2,3,4,5,6,7,8,9
 SPECIAL SYMBOLS ? ! @ # $ % & * ()+ -  =
_ | : ;etc..
 WHITE SPACES Blank space,Tab,New
line
TRIGRAPH
CHARACTERS
Many non-English keyboards do not support all
the characters.
For that C introduces the concept of “trigraph”
sequences to provide a way to enter certain
characters that are not available on some
keyboards.
Each trigraph sequence consists of three
characters(two questionmark followed by another
character). Ex. keyword not support square
brackets,
Ex. Trigraph Sequence Translation
??=, ??/ #,
??( , ??) [, ]
C TOKENS
TOKENS
CONSTANTS
KEYWORDS
VARIABLES
OPERATORS
SPECIAL
SYMBOL
STRING
KEYWORDS AND IDENTIFIERS
All keyword have fixed meanings and meanings cannot be changed.
Ex. break, else, do, while….
Identifiers refer to the names of variable, functions and arrays.
These are user defined names and consist of sequence of letters
and digits
Rules:-
First char must be alphabet.
Contain letters, digits, underscore not white space and keyword.
DIFFERENCE BETWEEN
CONSTANTS & VARIABLES
• CONSTANT is a quantity that doesn’t change.
• VARIABLE is a quantity that value can be changed respectively.
For example :
3X + Y = 20
Since 3 and 20 can not change, they are called constants, where as
the quantities X & Y can vary or change hence are called
variables.
TYPES OF C CONSTANTS
•
C Constants
Primary Constants Secondary Constants
Integer Constants
Real Constants
Character Constants
String constants
Array, Pointer ,
Structure , Union
Enum etc.
INTEGER CONSTANTS
- An integer constants refers to a sequence of digits
Three types
Decimal: Set of digits,0 through 9
123, -87, 0, +56 <- valid $1000, 15 750, (20,000) <-Invalid
Octal: Combination of 0 to 7 with leading zero. i.e. 075, 051, 0435 are
octal
Hexadecimal: Sequence of digits 0-9,A..F/a..f …..
REAL CONSTANTS(FLOATING POINT)
- to represent varying entity like prices. it contain fractional parts.
in decimal notation 34.32, -0.56, .4555 , 0.00054 etc.
In exponential notation(or scientific) 215.65 may be written as
2.1565e2 also valid
More 0.65e4 ,12e-2, 3.18E3.
SINGLE CHARACTER CONSTANTS
-a single character enclosed within a pair of single quote marks i.e
‘y’ , ‘4’, ‘;’ , ‘ ‘, etc.
- character constants have integer values known as ASCII (American
Standard Code for Information Interchange) values.
i.e. printf(“%d”,’a’); will print no. 97, the ascii value of the letter a.
While printf(“%c”,97); will print --- a
*error in book statement instead of ’97’ it should be only 97
STRING CONSTANTS
-sequence of characters enclosed in double quotes like
“hello!” , “hi 18”, “well done”, “a”
Remember that “x” and ‘x’ is different because ‘x’ has
equivalent integer value in ASCII.
String constants are normally used like displaying
menu/messages.
BACKSLASH CHARACTER CONSTANTS
- used in output functions…
- ‘n’ stands for new line character
- ‘b’ for back space
- ‘t’ for making horizontal tab
all above represents one character, although they consist of two
chars.
These char combination are known as “escape sequences”
VARIABLES
A specific place where specific data is stored
variable name : to access/use the data stored at the specific
place.
A variable is a data name that may be used to store a data value
i.e. you want to store two numbers 423 and 54.
No1 No2
423 54
RULES FOR DEFINING A VARIABLE
1. They must begin with a letter & no special symbols are used
without underscore.( _ )
i.e. total, mark1, ave_mark (Valid)
3mark, 345 (Invalid)
2. The length should not be normally more than 8 characters,
since only the first 8 characters are treated as significant by
the compiler.
i.e. average_weight & average_height
will be treated same.
RULES FOR DEFINING A VARIABLE
3. Uppercase and lowercase are significant.
i.e. the variable Total is not the same as total or TOTAL.
4. The variable name should not be a keyword.
5. White space is not allowed.
i.e. variable name ‘my total’ is invalid.
DATA TYPES
Classes of data types :
Primary data types
User defined data types
Derived data types
Basically C supports four Primary data types :-
integer (int) , character (char), floating point (float) , double
precision floating point (double).
PRIMARY DATA TYPES
TYPE SIZE RANGE
Char 1 byte -128 to 127
Int 2 byte -32,768 to 32,767
Float 4 byte 3.4e-38 to 3.4e+38
Double 8 byte 1.7e-308 to 1.7e+308
Long int 4 byte -232
to 232
Long double 10 byte +/- 3.4*104932
QUALIFIER
Signed : Indicates that the data can be positive or negative
Unsigned : Indicates that data to store is positive only…
Short : Data to store will require less memory
Long : Data to store will require more memory…
RANGE OF DATA TYPE
• –32768 to 32767. ( from -215
to 215)
• So, here first bit is used for sign. Means if it is 0 then
+ve no and 1 then –ve no. so, only other 15 bits are
used for magnitude. And so that range is –32768 to
32767.
1
SIGN BIT
TYPE SHORT FORM SYMBOL
character char %c
Signed integer int %d
Unsigned int Same %u
real float %f
double double %lf
Long double Same %Lf
Signed long int Same %ld
Unsigned long int Same %lu
DECLARATION OF VARIABLES
data_type v1,v2,….,vn;
Where v1,v2, … vn are variable names.
i.e. int maximum;
will have two bytes memory allocated and the name ‘maximum’
associated with it.
(by default the int is considered as signed, so range -32768 to
32767)
i.e. unsigned int age;
then 2 bytes allocated but the range will be 0 to 65535.
ASSIGNING VALUES TO VARIABLE
assignment operator
int num1,num2,sum;
sum = num1 + num2;
No1=no2=no3; also possible…
int no1=10; also possible …. Initialization at the time of declaration.
char choice;
choice = ‘y’;
or scanf(“%c”,&choice);
USER DEFINED TYPE DECLARATION
Type definition that allows programmers to define an
identifier/name that would represent an existing data type….
general form: typedef type identifier;
i.e. typedef int marks_inc
So, now onward when we require to store marks of c subject we will
create variable of type marks_inc like,
marks_inc m_stu1;
typedef just increase readability via creating meaningful data type
names, it can’t create a new datatype.
ENUMERATED DATA TYPE
Suppose u want to store week days like
Sunday, Monday,…,
So, u know the possible values in advance …. Can be done using
enumerated data type
enum identifier {value1,value2,..};
i.e enum day {Mon,Tue,Wed,Thur,Fri,Sat,Sun};
enum day week_st;
So, here week_st can have any possible value from the list
CONTINUING ENUM
Here by default
Enumeration constant Mon is assigned 0,
Tue assigned 1, Wed is assigned 2, and so on.
However automatic assignments can be overridden by …..
enum day {Mon=10,Tue,Wed,…..};
Now As Mon is having 10, Tue will have one more 11, Wed will have
12, and so on.
Q. int x; x = Wed – Mon; x = ?
VARIABLE’S STORAGE CLASS
Provides information about the location and visibility/scope of a
variable.
There are four storage class specifiers auto,register,static,extern.
auto variables
……. defined within a function
…. gets memory when the function is executing
……destroys when the function is over
…..local to that function so can’t be used in outside function
…. Gets garbage initialized..
…GLOABAL
the variable declare outside any function before main
known as global variable.
It can be used in all the functions after the declaration
of it.
Note ::
Global is External variable…
External and static variable are initialized to zero by
default… .while auto variable contains garbage .. Until
they are initialized.
DECLARING A IDENTIFIER AS
CONSTANT
Suppose u want to make some identifier whose value need not to be
changed during the execution …
const int class_size = 40;
So, you can use const qualifier.
This ensures that
x= class_size; valid
class_size = 10; invalid because as class_size is constant and
can’t change it’s value.
OVERFLOW OF DATA
- when the value of a variable is either too big or too small for the
data type to hold…
- ‘C compiler does not provide any warning or indication of integer
overflow.
- Programmer must take care for the type and range of input
possible
THE GENERAL FORMAT OF #DEFINE
A constant can be defined as follows:
#define symbolic-name value of constant
Valid examples are:
#define PI 3.14159
#define MAX 100
RULES APPLY TO #DEFINE
1.Symbolic name have the same form as variable names. But usually we
are using CAPITALS for symbolic names. But that is not a rule.
#define MAX 200
2.No blank space between the pound sign’#’ and the word define is
permitted.
# define MAX 200 <- Not permitted
3.’#’ must be the first character in the line.
4.A blank space is required between #define and symbolic name and
between the symbolic name and value.
CONTINUE…CONTINUE…
5.#define statements must not end with a semicolon.
#define PI 3.1415; <- Not valid
6.After definition, the symbolic name should not be assigned any
other value within the program using an assignment statement.
i.e. #define STRENGTH 100
main()
{
STRENGTH = 200;
}
Is illegal.
List of Number System Conversion Programs in C
1.C program to convert number from Decimal to Binary.
2.C program to convert number from Decimal to Octal.
3.C program to convert number from Decimal to Hexadecimal.
4.C program to convert number from Binary to Decimal.
5.C program to convert number from Octal to Decimal.
6.C program to convert number from Hexadecimal to Decimal.
7.Check EVEN or ODD program using switch
8.Calculator program with Basic operations using switch
9.Check VOWEL or CONSONANT program using switch
10.Print all PRIME numbers from 1 to N using C program
11.Print all Leap Years from 1 to N using C program
12.Print Square, Cube and Square Root using C program
13.Print number from 1 to N with EVEN and ODD message using C
program
14.Sum of first N natural numbers using C program
Thank you

More Related Content

What's hot

What's hot (20)

1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
C notes
C notesC notes
C notes
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii ppt
 
Programming in c
Programming in cProgramming in c
Programming in c
 
C programming course material
C programming course materialC programming course material
C programming course material
 
Assignment4
Assignment4Assignment4
Assignment4
 
Unit 1 cd
Unit 1 cdUnit 1 cd
Unit 1 cd
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Cs6660 compiler design
Cs6660 compiler designCs6660 compiler design
Cs6660 compiler design
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
 
7 compiler lab
7 compiler lab 7 compiler lab
7 compiler lab
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Handout#03
Handout#03Handout#03
Handout#03
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
A brief introduction to C Language
A brief introduction to C LanguageA brief introduction to C Language
A brief introduction to C Language
 
Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)Learn c language Important topics ( Easy & Logical, & smart way of learning)
Learn c language Important topics ( Easy & Logical, & smart way of learning)
 

Viewers also liked (16)

Array within a class
Array within a classArray within a class
Array within a class
 
Structure in c
Structure in cStructure in c
Structure in c
 
Structure in c
Structure in cStructure in c
Structure in c
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
Structure in C
Structure in CStructure in C
Structure in C
 
structure and union
structure and unionstructure and union
structure and union
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
0. Course Introduction
0. Course Introduction0. Course Introduction
0. Course Introduction
 
Array in C
Array in CArray in C
Array in C
 
Arrays
ArraysArrays
Arrays
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Functions
FunctionsFunctions
Functions
 
Recursion
RecursionRecursion
Recursion
 
Lecture18 structurein c.ppt
Lecture18 structurein c.pptLecture18 structurein c.ppt
Lecture18 structurein c.ppt
 

Similar to Lecture 01 2017

490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.pptManiMala75
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.pptManiMala75
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptxsscprep9
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centrejatin batra
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptANISHYAPIT
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxsaivasu4
 
C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptxAnshSrivastava48
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingPreeti Kashyap
 
C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfComedyTechnology
 

Similar to Lecture 01 2017 (20)

490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
 
history of c.ppt
history of c.ppthistory of c.ppt
history of c.ppt
 
C language ppt
C language pptC language ppt
C language ppt
 
C programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer CentreC programming Training in Ambala ! Batra Computer Centre
C programming Training in Ambala ! Batra Computer Centre
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 
8844632.ppt
8844632.ppt8844632.ppt
8844632.ppt
 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptx
 
c#.pptx
c#.pptxc#.pptx
c#.pptx
 
Chapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this pptChapter-2 edited on Programming in Can refer this ppt
Chapter-2 edited on Programming in Can refer this ppt
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptx
 
Cnotes
CnotesCnotes
Cnotes
 
7986-lect 7.pdf
7986-lect 7.pdf7986-lect 7.pdf
7986-lect 7.pdf
 
Presentation 2.ppt
Presentation 2.pptPresentation 2.ppt
Presentation 2.ppt
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
C programming.pdf
C programming.pdfC programming.pdf
C programming.pdf
 
C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptx
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdf
 

More from Jesmin Akhter

More from Jesmin Akhter (6)

Lecture 11
Lecture  11Lecture  11
Lecture 11
 
Lecture 10
Lecture  10Lecture  10
Lecture 10
 
Lecture 11
Lecture  11Lecture  11
Lecture 11
 
Lecture 10
Lecture  10Lecture  10
Lecture 10
 
1605.01126
1605.011261605.01126
1605.01126
 
Lecture 05 2017
Lecture 05 2017Lecture 05 2017
Lecture 05 2017
 

Recently uploaded

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Recently uploaded (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

Lecture 01 2017

  • 1. Programming in C Lecture 01 By- Jesmin Akhter Associate Professor, IIT, Jahangirnagar University
  • 2. TEXT BOOK Programming in ANCI ‘C By: E Balagurusamy. TMH
  • 4. Importance of C • C is the base language of any other programming language. • To be a Good Programmer one must know fundamentals of C programming language. • It is a robust language. • Whose rich set of built in functions and operators can be used to write any complex program. • Programs written in ‘C’ are efficient and fast. • Because of variety of data types and powerful operators • Highly Portable. (related to OS) – C program written for one computer can be run on another with little or no modification • Well suited for structured programming • Ability to extend itself • Well suited for writing system software – UNIX, MS-DOS operating system,
  • 5. Program & Programming Language • Program:- A Set of instructions which carried out by processor for some Specific input, generates specific output. • Programming language:- A specific manner of writing a program with some Predefined rules, symbols & their use as a part of language. – i.e. Pascal, C, C++, VC++, JAVA, VB.
  • 6. Basic structure of ‘C’ 1) Documentation Section :- It has set of comment lines(name of program, author details). What is Comment line??  To guide a programmer. To write a note for function,operation,logic in between a program.  Non-executable statement.  Can’t be nested. e.g:- /* Hello /* abc */ Hi */ ERROR.
  • 7. 2)Link Section :- It provides instructions to the compiler to link function from the system library. # include Directive:-  To access the functions which are stored in the library, it is necessary to tell the compiler , about the file to be accessed. Syntax:- #include<stdio.h>  stdio.h is header file.
  • 8. 3) Definition Section It defines all symbolic constants. #define instruction defines value to a symbolic constant. #define:- It is a preprocessor compiler directive, not a statement. Therefore it should not end with a semicolon. Generally written in uppercase.
  • 9. 4)Global Declaration Section Some variables that are used in more than one function, such variables (global variables) declared in the global declaration section. It also declares all the user-defined function.
  • 10. 5) Main() function section: Every ‘C’ program must have one main() function section. It contains two parts 1) Declaration part: It declares all variables used in the executable part. 2) Executable part: It has atleast one statement. Ex: main( ) = main (void) No arguments Explicitly indicate no arguments
  • 11. 5) Basic structure of C Programs: Documentation section Link Section Definition Section Global Declaration Section main() function section { Declaration part Executable part } Subprogram section Function1 Function2 … user defined function
  • 12. How to run a program? • There are two ways to run programs written in a high-level language. – The most common is to compile the program – The other method is to pass the program through an interpreter.
  • 13. Why Compiler • As machine (a processor) can operate on binary code instruction only….. • If we use higher level language then … – For execution of the program we must convert it to lower level / machine level code. • Compiler is a program that translates source code into object code. • The compiler derives its name from the way it works, looking at the entire piece of source code and collecting and reorganizing the instructions.
  • 14. Interpreter • Analyzes and executes each line of source code without looking at the entire program. Advantage of interpreter: • It can execute a program immediately. – Compilers require some time before an executable program emerges. • But, – However, programs produced by compilers run much faster than the same programs executed by an interpreter.
  • 15. C Compiler - checks for syntax errors if any - on success coverts ‘C source code into object code form – which is nearer to machine…
  • 16. Linker: A linker is a program that combines object modules to form an executable program.
  • 17.
  • 18. Types of languages (I)Lower level languages:- Languages which are very near to machine…. I.e. machine language, Assembly language. (II) Higher level languages:- Languages which are very near to programmer rather than to machine…. I.e. C++,Visual C++,Visual basic,Java.
  • 19.
  • 20. BlockDiagram: Represents only -> what should be the input? -> what will be the output? - One need not to worry about how the result generated…. - or what will be the logic for the program?
  • 21. Input No1. & No2. PROGRAM No1 + No2 Output Block Diagram for making addition of two numbers
  • 22. Algorithm Specifies steps of doing the things Irrespective of any programming language Example: Addition of two numbers Step 1: [Read two numbers] Read(no1) Read(no2) Step 2:[add two numbers into sum] summation = no1 + no2 Step 3:[Display the result] write (summation)
  • 23. Flowchart Represents the flow of program Symbols:- Start-Begin/End Input/Output Rectangle Process box/operation box Decision Box Connector
  • 24. Flowchart-example Example: To add two numbers and display the result. Start SUMMATION = NO1 + NO2 End Read No1 and No2 from user Write Summation on monitor
  • 25. Files ,directory, file extension Files:- storage of logically related data Directory:- Placeholder which can store files and subdirectories within them. File Extension:- special postfix attached to each file which indicates type of the file.
  • 26. Sample C program:- /* print hello*/ #include<stdio.h> /* link section*/ void main() /* execution of program*/ { print(“hello world”); /*executable statement*/ }
  • 28. C AS A LANGUAGE • Interface between computer & human being. ALPHABETS WORDS SENTENCES PARAGRAPH Alphabets, digits special symbol Constants, Variables, Keywords Instructions Program
  • 29. C CHARACTER SET  ALPHABETS A,B…………Z a,b………….z  DIGITS 0,1,2,3,4,5,6,7,8,9  SPECIAL SYMBOLS ? ! @ # $ % & * ()+ - = _ | : ;etc..  WHITE SPACES Blank space,Tab,New line
  • 30. TRIGRAPH CHARACTERS Many non-English keyboards do not support all the characters. For that C introduces the concept of “trigraph” sequences to provide a way to enter certain characters that are not available on some keyboards. Each trigraph sequence consists of three characters(two questionmark followed by another character). Ex. keyword not support square brackets, Ex. Trigraph Sequence Translation ??=, ??/ #, ??( , ??) [, ]
  • 32. KEYWORDS AND IDENTIFIERS All keyword have fixed meanings and meanings cannot be changed. Ex. break, else, do, while…. Identifiers refer to the names of variable, functions and arrays. These are user defined names and consist of sequence of letters and digits Rules:- First char must be alphabet. Contain letters, digits, underscore not white space and keyword.
  • 33. DIFFERENCE BETWEEN CONSTANTS & VARIABLES • CONSTANT is a quantity that doesn’t change. • VARIABLE is a quantity that value can be changed respectively. For example : 3X + Y = 20 Since 3 and 20 can not change, they are called constants, where as the quantities X & Y can vary or change hence are called variables.
  • 34. TYPES OF C CONSTANTS • C Constants Primary Constants Secondary Constants Integer Constants Real Constants Character Constants String constants Array, Pointer , Structure , Union Enum etc.
  • 35. INTEGER CONSTANTS - An integer constants refers to a sequence of digits Three types Decimal: Set of digits,0 through 9 123, -87, 0, +56 <- valid $1000, 15 750, (20,000) <-Invalid Octal: Combination of 0 to 7 with leading zero. i.e. 075, 051, 0435 are octal Hexadecimal: Sequence of digits 0-9,A..F/a..f …..
  • 36. REAL CONSTANTS(FLOATING POINT) - to represent varying entity like prices. it contain fractional parts. in decimal notation 34.32, -0.56, .4555 , 0.00054 etc. In exponential notation(or scientific) 215.65 may be written as 2.1565e2 also valid More 0.65e4 ,12e-2, 3.18E3.
  • 37. SINGLE CHARACTER CONSTANTS -a single character enclosed within a pair of single quote marks i.e ‘y’ , ‘4’, ‘;’ , ‘ ‘, etc. - character constants have integer values known as ASCII (American Standard Code for Information Interchange) values. i.e. printf(“%d”,’a’); will print no. 97, the ascii value of the letter a. While printf(“%c”,97); will print --- a *error in book statement instead of ’97’ it should be only 97
  • 38. STRING CONSTANTS -sequence of characters enclosed in double quotes like “hello!” , “hi 18”, “well done”, “a” Remember that “x” and ‘x’ is different because ‘x’ has equivalent integer value in ASCII. String constants are normally used like displaying menu/messages.
  • 39. BACKSLASH CHARACTER CONSTANTS - used in output functions… - ‘n’ stands for new line character - ‘b’ for back space - ‘t’ for making horizontal tab all above represents one character, although they consist of two chars. These char combination are known as “escape sequences”
  • 40. VARIABLES A specific place where specific data is stored variable name : to access/use the data stored at the specific place. A variable is a data name that may be used to store a data value i.e. you want to store two numbers 423 and 54. No1 No2 423 54
  • 41. RULES FOR DEFINING A VARIABLE 1. They must begin with a letter & no special symbols are used without underscore.( _ ) i.e. total, mark1, ave_mark (Valid) 3mark, 345 (Invalid) 2. The length should not be normally more than 8 characters, since only the first 8 characters are treated as significant by the compiler. i.e. average_weight & average_height will be treated same.
  • 42. RULES FOR DEFINING A VARIABLE 3. Uppercase and lowercase are significant. i.e. the variable Total is not the same as total or TOTAL. 4. The variable name should not be a keyword. 5. White space is not allowed. i.e. variable name ‘my total’ is invalid.
  • 43. DATA TYPES Classes of data types : Primary data types User defined data types Derived data types Basically C supports four Primary data types :- integer (int) , character (char), floating point (float) , double precision floating point (double).
  • 44. PRIMARY DATA TYPES TYPE SIZE RANGE Char 1 byte -128 to 127 Int 2 byte -32,768 to 32,767 Float 4 byte 3.4e-38 to 3.4e+38 Double 8 byte 1.7e-308 to 1.7e+308 Long int 4 byte -232 to 232 Long double 10 byte +/- 3.4*104932
  • 45. QUALIFIER Signed : Indicates that the data can be positive or negative Unsigned : Indicates that data to store is positive only… Short : Data to store will require less memory Long : Data to store will require more memory…
  • 46. RANGE OF DATA TYPE • –32768 to 32767. ( from -215 to 215) • So, here first bit is used for sign. Means if it is 0 then +ve no and 1 then –ve no. so, only other 15 bits are used for magnitude. And so that range is –32768 to 32767. 1 SIGN BIT
  • 47. TYPE SHORT FORM SYMBOL character char %c Signed integer int %d Unsigned int Same %u real float %f double double %lf Long double Same %Lf Signed long int Same %ld Unsigned long int Same %lu
  • 48. DECLARATION OF VARIABLES data_type v1,v2,….,vn; Where v1,v2, … vn are variable names. i.e. int maximum; will have two bytes memory allocated and the name ‘maximum’ associated with it. (by default the int is considered as signed, so range -32768 to 32767) i.e. unsigned int age; then 2 bytes allocated but the range will be 0 to 65535.
  • 49. ASSIGNING VALUES TO VARIABLE assignment operator int num1,num2,sum; sum = num1 + num2; No1=no2=no3; also possible… int no1=10; also possible …. Initialization at the time of declaration. char choice; choice = ‘y’; or scanf(“%c”,&choice);
  • 50. USER DEFINED TYPE DECLARATION Type definition that allows programmers to define an identifier/name that would represent an existing data type…. general form: typedef type identifier; i.e. typedef int marks_inc So, now onward when we require to store marks of c subject we will create variable of type marks_inc like, marks_inc m_stu1; typedef just increase readability via creating meaningful data type names, it can’t create a new datatype.
  • 51. ENUMERATED DATA TYPE Suppose u want to store week days like Sunday, Monday,…, So, u know the possible values in advance …. Can be done using enumerated data type enum identifier {value1,value2,..}; i.e enum day {Mon,Tue,Wed,Thur,Fri,Sat,Sun}; enum day week_st; So, here week_st can have any possible value from the list
  • 52. CONTINUING ENUM Here by default Enumeration constant Mon is assigned 0, Tue assigned 1, Wed is assigned 2, and so on. However automatic assignments can be overridden by ….. enum day {Mon=10,Tue,Wed,…..}; Now As Mon is having 10, Tue will have one more 11, Wed will have 12, and so on. Q. int x; x = Wed – Mon; x = ?
  • 53. VARIABLE’S STORAGE CLASS Provides information about the location and visibility/scope of a variable. There are four storage class specifiers auto,register,static,extern. auto variables ……. defined within a function …. gets memory when the function is executing ……destroys when the function is over …..local to that function so can’t be used in outside function …. Gets garbage initialized..
  • 54. …GLOABAL the variable declare outside any function before main known as global variable. It can be used in all the functions after the declaration of it. Note :: Global is External variable… External and static variable are initialized to zero by default… .while auto variable contains garbage .. Until they are initialized.
  • 55. DECLARING A IDENTIFIER AS CONSTANT Suppose u want to make some identifier whose value need not to be changed during the execution … const int class_size = 40; So, you can use const qualifier. This ensures that x= class_size; valid class_size = 10; invalid because as class_size is constant and can’t change it’s value.
  • 56. OVERFLOW OF DATA - when the value of a variable is either too big or too small for the data type to hold… - ‘C compiler does not provide any warning or indication of integer overflow. - Programmer must take care for the type and range of input possible
  • 57. THE GENERAL FORMAT OF #DEFINE A constant can be defined as follows: #define symbolic-name value of constant Valid examples are: #define PI 3.14159 #define MAX 100
  • 58. RULES APPLY TO #DEFINE 1.Symbolic name have the same form as variable names. But usually we are using CAPITALS for symbolic names. But that is not a rule. #define MAX 200 2.No blank space between the pound sign’#’ and the word define is permitted. # define MAX 200 <- Not permitted 3.’#’ must be the first character in the line. 4.A blank space is required between #define and symbolic name and between the symbolic name and value.
  • 59. CONTINUE…CONTINUE… 5.#define statements must not end with a semicolon. #define PI 3.1415; <- Not valid 6.After definition, the symbolic name should not be assigned any other value within the program using an assignment statement. i.e. #define STRENGTH 100 main() { STRENGTH = 200; } Is illegal.
  • 60. List of Number System Conversion Programs in C 1.C program to convert number from Decimal to Binary. 2.C program to convert number from Decimal to Octal. 3.C program to convert number from Decimal to Hexadecimal. 4.C program to convert number from Binary to Decimal. 5.C program to convert number from Octal to Decimal. 6.C program to convert number from Hexadecimal to Decimal. 7.Check EVEN or ODD program using switch 8.Calculator program with Basic operations using switch 9.Check VOWEL or CONSONANT program using switch 10.Print all PRIME numbers from 1 to N using C program 11.Print all Leap Years from 1 to N using C program 12.Print Square, Cube and Square Root using C program 13.Print number from 1 to N with EVEN and ODD message using C program 14.Sum of first N natural numbers using C program

Editor's Notes

  1. Trigraph sequences allow C programs to be written using only the ISO (International Standards Organization) Invariant Code Set. Trigraphs are sequences of three characters (introduced by two consecutive question marks) that the compiler replaces with their corresponding punctuation characters.