SAMRAT PRITHVIRAJ CHAUHAN
GOVERNMENT COLLEGE (AJMER)
DEPARTMENT OF CHEMISTRY
 SUBMITTED TO : DEPARTMENT OF CHEMISTRY
 SUBMITTED BY :
HRITIK POONIYA [M.Sc.(PREVIOUS)]
 TOPIC : ‘C’-PROGRAMMING
C-programming
CONTENT
1. OVERVIEW OF “C”
2. TERMS RELATED TO ‘C’ PROGRAM
3. CONSTANTS
4. VARIABLES
5. DATA TYPES
6. OPERATORS AND EXPRESSIONS
7. DECISION MAKING AND BRANCHING
8. If, If……Else AND goto STATEMENTS
9. DECISION MAKING AND LOOPING
10. While , Do AND For STATEMENT
11. C – PROGRAM TO CALCULATE PRESSURE USING
VANDER WAALS EQUATION
OVERVIEW OF “C”
DEFINATION –
‘C’ may be
defined as a
structured,
high- level,
machine
independent
language which
allows software
developers to
develop programs
without worrying
about the
hardware
platforms where
they will be
HISTORY OF “C” -
TERMS RELATED TO ‘C’-
PROGRAM
CHARACTER SET: A subset of characters is available that can
be used on computers . Characters in ‘C’ are grouped into
following:
‘C’- TOKENS: Individual words and punctuation marks are
called Tokens. Similarly, in ‘C’-program smallest
individuals units are known as ‘C-Tokens’.
TERMS RELATED TO ‘C’-
PROGRAM
KEYWORDS: Keywords serve as basic building block for program
statements which have fixed meaning and these cannot be
changed. All must be written in lowercase.
IDENTIFIERS: It refers to –the names of variables, functions
and arrays; which are user-defined names and consist of a
sequence of letters and digits, with a letter as a first
character. It is usually used as a link between two words in
long identifiers.
RULES FOR IDENTIFIERS :
1. First character must be an alphabet or underscore.
2. Must consist of only letters, digits or underscore.
3. Only first 31 characters are significant.
4. Cannot use a keyword.
5. Must not contain white space.
CONSTANTS
CONSTANTS
NUMERIC CONSTANTS
INTEGER
CONSTANTS
CHARACTER CONSTANTS
SINGLE
CHARACTER
CONSTANTS
REAL
CONSTANTS
STRING
CONSTANTS
DECIMAL
INTEGER
OCTAL
INTEGER
HEXADECIMAL
INTEGER
Constants in ‘C’ refer to fixed values that do not change
during execution of a program. ‘C’ supports several types of
constants →
VARIABLES
Variable is a data name that may be used to store a
data value and may take different values at different
times during execution.
A variable name can be chosen by the programmer in a
meaningful way so as to reflect its function or nature in
program, such as – Average, Height, Weight, Total,
Counter_1, Class_strength, etc.
RULES FOR VARIABLES :
1. They must begin with a letter. Some systems permit
underscore as first character.
2. ANSI standard recognizes a length of 31 characters,
since only first 8 characters. However, length should
not be normally more than 8 characters are treated as
significant by many compilers.
3. Uppercase and Lowercase are significant.(Total is not
same as TOTAL or total.)
4. It should not be keyword.
5. White space is not allowed.
DATA-TYPES
ANSI C SUPPORTS THREE CLASSES OF DATA
TYPES –
1. PRIMARY OR FUNDAMENTAL DATA TYPES –
All C compilers support five
fundamental data types, namely
(int), (char), (float), (double) and
void and their extended data types.
2. DERIVED DATA TYPES – These are data
types that are derived from the
fundamental data types. They are
used to create more complex data
types that can hold multiple values
or values of different types. The
main derived data types are ARRAYS
and POINTERS.
3. USER-DEFINED DATA TYPES – These are
custom data types created by users
to suits their specific needs. These
data types are not built-in to the
programming language but are instead
defined by user using existing data
types. User defined data types
including Enums,Structs,Unions,
typedefs.
‘C’ language is
rich in its data
types . Storage
representations and
machine
instructions to
handle constants
differ from machine
to machine. The
variety of data
types available
allow the
programmer to
select the type
appropriate to
needs of the
application as well
as machine.
INTRODUCTION
:
OPERATORS AND
EXPRESSIONS
An operator is a symbol that tells the computer to
perform certain mathematical or logical
manipulations . These are used in programs to
manipulate data and variables. They usually form a
part of mathematical or logical expressions. ‘C’
operators can be classified into a number of
categories. They include –
1.ARITHMETIC OPERATORS – Its include operators as
+,-,*,/,% and divide into three categories, namely
Integer arithmetic, Real arithmetic and mixed mode
arithmetic.
2.RELATIONAL OPERATORS – Its includes operators as
<,<=,>,>=,==,|= and relates two expressions.
3.LOGICAL OPERATORS – Its includes operators as &&
(LOGIC AND), ||(LOGIC OR), !(LOGIC NOT) and the
output is in value of 1 or 0.
4.ASSIGNMENT OPERATORS – Its include operator ‘=’ and
work as a shorthand form(v1op=exp;).
EXAMPLE- a=a+1 shorthand as a+=1.
5.INCREMENT & DECREMENT OPERATORS – Its includes
operators as ++m,--m and allows to increase or
decrease expressions(m) by 1,respectively.
6.BITWISE OPERATORS – Its includes operators as &
(bitwise AND), |(bitwise OR), ^(bitwise exclusive
OR), <<(shift left), >>(shift right) and these are
used for manipulation of data at bit level.
7.SPECIAL OPERATORS – ‘C’ supports some special
operators of interest such as the comma operator,
sizeof operator, pointer operator(&) and member
selection operators (. and →).
8.CONDITIONAL OPERATORS – It is also known as ternary
operator pair ‘?:’ is available in ‘C’ to construct
conditional expressions of the form :
[exp1?exp2:exp3]
DECISION MAKING AND
BRANCHING
We have a number of situations where we may have to
change the order of execution statements based on
certain conditions, or repeat a group of statements
until certain specified conditions are met.
This involves a kind of decision making to see
whether a particular condition has occurred or not
and then direct the computer to execute certain
statements accordingly.
‘C’ language possess such decision making
capabilities by supporting the following statements –
if statement, switch statement, ?: operator statement
and goto statement.
These statements are popularly known as ‘Decision
making statements’. Since these statements ‘control’
the flow of execution, they are also known as
‘control statements’.
if, if…else AND goto STATEMENT
(if) (if…else)
if (test
expression)
{
statement-
block;
}
statement-x
GENERAL FORM : GENERAL FORM :
FLOWCHART:
if (test expression)
{
true-block statement(s);
}
else
{
false-block statement(s);
}
statement-x
FLOWCHART:
(goto)
GENERAL FORM :
goto label;
--------------
--------------
--------------
label:
statement;
(FORWARD JUMP)
label:
statement;
--------------
--------------
--------------
goto label;
(BACKWARD
JUMP)
FLOWCHART:
DECISION MAKING AND LOOPING
On such occasions where the exact number of repetitions are known, there are
more convenient methods of looping in ‘C’. These looping capabilities enable us to
develop concise programs containing repetitive processes without the use of goto
statement.
A looping process would include following four steps:
1. Setting and initialization of a condition variable.
2. Execution of the statements in the loop.
3. Test for a specified value of condition variable for execution of loop.
4. Incrementing or updating the condition variable.
In looping, a sequence of statements are executed until some conditions for
termination of the loop are satisfied. A program loop consists two segments,
one known as Body of the Loop and other one known as Control statement. Control
statement tests certain conditions and then directs the repeated execution of
statements contained in the body of the loop.
Depending on the position of control statement in the loop, a control structure may
be classified either as the entry-controlled loop (pre-test loop) or as the exit-
controlled loop (post-test loop).
The ‘C’-language provides for three constructs for performing loop operations.
They are : while statement, do statement and for statement.
(ENTRY- CONTOLLED LOOP) (EXIT- CONTOLLED LOOP)
while,do..while AND for
STATEMENT (do…while)
do
{
body of the loop;
}
while (test condition)
GENERAL FORM :
FLOWCHART:
while (test condition)
{
body of the loop;
}
GENERAL FORM :
FLOWCHART:
(while)
(for)
for (initialization ;test-
condition; increment)
{
body of the loop;
}
GENERAL FORM : FLOWCHART:
for (initialization ;test-
condition; decrement)
{
body of the loop;
}
(INCREMENT FORM)
(DECREMENT FORM)
C – PROGRAM TO CALCULATE PRESSURE
USING VANDER WAALS EQUATION
VAN-DER WAALS EQUATION :
VAN-DER WAALS EQUATION FOR FIND OUT PRESSURE :
C – PROGRAM TO CALCULATE PRESSURE USING VANDER WAALS
EQUATION
‘MAIN.C’
FORM
:
OUTPUT
FORM
:
CALCULATION :
SUMMARY
‘C’ is a powerful and flexible
programming language that has influenced
many modern languages.
It is still widely used in system
programming, embedded systems, and
applications requiring high performance.
LEARNING ‘C’- Provides a solid
foundation for understanding other
programming languages and computer
science concepts.
REFERENCE
GeeksforGeeks.com
w3schools.com
tutorialspoint.com
ANSI C Book
“Inquire, Inspire, Innovate: The Power of
Questions.”
( “ASK YOUR QUESTIONS” )

C programming msc chemistry pankaj pandey

  • 1.
    SAMRAT PRITHVIRAJ CHAUHAN GOVERNMENTCOLLEGE (AJMER) DEPARTMENT OF CHEMISTRY  SUBMITTED TO : DEPARTMENT OF CHEMISTRY  SUBMITTED BY : HRITIK POONIYA [M.Sc.(PREVIOUS)]  TOPIC : ‘C’-PROGRAMMING
  • 2.
  • 3.
    CONTENT 1. OVERVIEW OF“C” 2. TERMS RELATED TO ‘C’ PROGRAM 3. CONSTANTS 4. VARIABLES 5. DATA TYPES 6. OPERATORS AND EXPRESSIONS 7. DECISION MAKING AND BRANCHING 8. If, If……Else AND goto STATEMENTS 9. DECISION MAKING AND LOOPING 10. While , Do AND For STATEMENT 11. C – PROGRAM TO CALCULATE PRESSURE USING VANDER WAALS EQUATION
  • 4.
    OVERVIEW OF “C” DEFINATION– ‘C’ may be defined as a structured, high- level, machine independent language which allows software developers to develop programs without worrying about the hardware platforms where they will be HISTORY OF “C” -
  • 5.
    TERMS RELATED TO‘C’- PROGRAM CHARACTER SET: A subset of characters is available that can be used on computers . Characters in ‘C’ are grouped into following: ‘C’- TOKENS: Individual words and punctuation marks are called Tokens. Similarly, in ‘C’-program smallest individuals units are known as ‘C-Tokens’.
  • 6.
    TERMS RELATED TO‘C’- PROGRAM KEYWORDS: Keywords serve as basic building block for program statements which have fixed meaning and these cannot be changed. All must be written in lowercase. IDENTIFIERS: It refers to –the names of variables, functions and arrays; which are user-defined names and consist of a sequence of letters and digits, with a letter as a first character. It is usually used as a link between two words in long identifiers. RULES FOR IDENTIFIERS : 1. First character must be an alphabet or underscore. 2. Must consist of only letters, digits or underscore. 3. Only first 31 characters are significant. 4. Cannot use a keyword. 5. Must not contain white space.
  • 7.
    CONSTANTS CONSTANTS NUMERIC CONSTANTS INTEGER CONSTANTS CHARACTER CONSTANTS SINGLE CHARACTER CONSTANTS REAL CONSTANTS STRING CONSTANTS DECIMAL INTEGER OCTAL INTEGER HEXADECIMAL INTEGER Constantsin ‘C’ refer to fixed values that do not change during execution of a program. ‘C’ supports several types of constants →
  • 8.
    VARIABLES Variable is adata name that may be used to store a data value and may take different values at different times during execution. A variable name can be chosen by the programmer in a meaningful way so as to reflect its function or nature in program, such as – Average, Height, Weight, Total, Counter_1, Class_strength, etc. RULES FOR VARIABLES : 1. They must begin with a letter. Some systems permit underscore as first character. 2. ANSI standard recognizes a length of 31 characters, since only first 8 characters. However, length should not be normally more than 8 characters are treated as significant by many compilers. 3. Uppercase and Lowercase are significant.(Total is not same as TOTAL or total.) 4. It should not be keyword. 5. White space is not allowed.
  • 9.
    DATA-TYPES ANSI C SUPPORTSTHREE CLASSES OF DATA TYPES – 1. PRIMARY OR FUNDAMENTAL DATA TYPES – All C compilers support five fundamental data types, namely (int), (char), (float), (double) and void and their extended data types. 2. DERIVED DATA TYPES – These are data types that are derived from the fundamental data types. They are used to create more complex data types that can hold multiple values or values of different types. The main derived data types are ARRAYS and POINTERS. 3. USER-DEFINED DATA TYPES – These are custom data types created by users to suits their specific needs. These data types are not built-in to the programming language but are instead defined by user using existing data types. User defined data types including Enums,Structs,Unions, typedefs. ‘C’ language is rich in its data types . Storage representations and machine instructions to handle constants differ from machine to machine. The variety of data types available allow the programmer to select the type appropriate to needs of the application as well as machine. INTRODUCTION :
  • 10.
    OPERATORS AND EXPRESSIONS An operatoris a symbol that tells the computer to perform certain mathematical or logical manipulations . These are used in programs to manipulate data and variables. They usually form a part of mathematical or logical expressions. ‘C’ operators can be classified into a number of categories. They include – 1.ARITHMETIC OPERATORS – Its include operators as +,-,*,/,% and divide into three categories, namely Integer arithmetic, Real arithmetic and mixed mode arithmetic. 2.RELATIONAL OPERATORS – Its includes operators as <,<=,>,>=,==,|= and relates two expressions. 3.LOGICAL OPERATORS – Its includes operators as && (LOGIC AND), ||(LOGIC OR), !(LOGIC NOT) and the output is in value of 1 or 0.
  • 11.
    4.ASSIGNMENT OPERATORS –Its include operator ‘=’ and work as a shorthand form(v1op=exp;). EXAMPLE- a=a+1 shorthand as a+=1. 5.INCREMENT & DECREMENT OPERATORS – Its includes operators as ++m,--m and allows to increase or decrease expressions(m) by 1,respectively. 6.BITWISE OPERATORS – Its includes operators as & (bitwise AND), |(bitwise OR), ^(bitwise exclusive OR), <<(shift left), >>(shift right) and these are used for manipulation of data at bit level. 7.SPECIAL OPERATORS – ‘C’ supports some special operators of interest such as the comma operator, sizeof operator, pointer operator(&) and member selection operators (. and →). 8.CONDITIONAL OPERATORS – It is also known as ternary operator pair ‘?:’ is available in ‘C’ to construct conditional expressions of the form : [exp1?exp2:exp3]
  • 12.
    DECISION MAKING AND BRANCHING Wehave a number of situations where we may have to change the order of execution statements based on certain conditions, or repeat a group of statements until certain specified conditions are met. This involves a kind of decision making to see whether a particular condition has occurred or not and then direct the computer to execute certain statements accordingly. ‘C’ language possess such decision making capabilities by supporting the following statements – if statement, switch statement, ?: operator statement and goto statement. These statements are popularly known as ‘Decision making statements’. Since these statements ‘control’ the flow of execution, they are also known as ‘control statements’.
  • 13.
    if, if…else ANDgoto STATEMENT (if) (if…else) if (test expression) { statement- block; } statement-x GENERAL FORM : GENERAL FORM : FLOWCHART: if (test expression) { true-block statement(s); } else { false-block statement(s); } statement-x FLOWCHART:
  • 14.
    (goto) GENERAL FORM : gotolabel; -------------- -------------- -------------- label: statement; (FORWARD JUMP) label: statement; -------------- -------------- -------------- goto label; (BACKWARD JUMP) FLOWCHART:
  • 15.
    DECISION MAKING ANDLOOPING On such occasions where the exact number of repetitions are known, there are more convenient methods of looping in ‘C’. These looping capabilities enable us to develop concise programs containing repetitive processes without the use of goto statement. A looping process would include following four steps: 1. Setting and initialization of a condition variable. 2. Execution of the statements in the loop. 3. Test for a specified value of condition variable for execution of loop. 4. Incrementing or updating the condition variable. In looping, a sequence of statements are executed until some conditions for termination of the loop are satisfied. A program loop consists two segments, one known as Body of the Loop and other one known as Control statement. Control statement tests certain conditions and then directs the repeated execution of statements contained in the body of the loop. Depending on the position of control statement in the loop, a control structure may be classified either as the entry-controlled loop (pre-test loop) or as the exit- controlled loop (post-test loop). The ‘C’-language provides for three constructs for performing loop operations. They are : while statement, do statement and for statement.
  • 16.
    (ENTRY- CONTOLLED LOOP)(EXIT- CONTOLLED LOOP)
  • 17.
    while,do..while AND for STATEMENT(do…while) do { body of the loop; } while (test condition) GENERAL FORM : FLOWCHART: while (test condition) { body of the loop; } GENERAL FORM : FLOWCHART: (while)
  • 18.
    (for) for (initialization ;test- condition;increment) { body of the loop; } GENERAL FORM : FLOWCHART: for (initialization ;test- condition; decrement) { body of the loop; } (INCREMENT FORM) (DECREMENT FORM)
  • 19.
    C – PROGRAMTO CALCULATE PRESSURE USING VANDER WAALS EQUATION VAN-DER WAALS EQUATION : VAN-DER WAALS EQUATION FOR FIND OUT PRESSURE :
  • 20.
    C – PROGRAMTO CALCULATE PRESSURE USING VANDER WAALS EQUATION ‘MAIN.C’ FORM :
  • 21.
  • 22.
    SUMMARY ‘C’ is apowerful and flexible programming language that has influenced many modern languages. It is still widely used in system programming, embedded systems, and applications requiring high performance. LEARNING ‘C’- Provides a solid foundation for understanding other programming languages and computer science concepts.
  • 23.
  • 24.
    “Inquire, Inspire, Innovate:The Power of Questions.” ( “ASK YOUR QUESTIONS” )