CH 01

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 18

Structure Programming

Using C

German University Bangladesh(GUB)


Computer Science and Engineering(CSE)
Rathindra Nath Mohalder
Lecturer
Chapter 01: Introduction
What is programming Language?
All human beings communicate each other by
their own languages. If computer needs to
communicate with other so they designed the
Programming language.
It is intermediate between human being and
machine. It is also refer as computer language.
Computer follow the instructions given by the
programmer and its perform the tasks.
Programs are set of instructions and that is
called software.
Levels of programming language
3 levels of programming language
(i)Low Level Languages
(ii) Middle Level Languages
(iii) High Level Languages

(i)Low level languages


Low level language is a machine code. It does not need any
compiler or interpreter for run. it is used to writing operating
systems, firmware and micro controllers. Directly it can
manage the memory.
Examples:
Assembly and machine code
Levels of programming language
(ii) Middle level languages
Middle level language is used to write operating system as well as
application programming. It has virtual machines to compile and
interpreted the languages. Easy to reason about the program flow. It does
not provide all built in functions available in high level languages.
Examples:
C, C++
(iii) High level languages
High level language is easy to read, write and maintain. It must be
translated into machine language/code by using interpreter or compiler.
process of developing a program is more simpler and understandable.
Examples:
Java , python, perl, ruby
What is C ?
C is a programming language developed at AT & T’s Bell Laboratories of
USA in 1972. It was designed and written by a man named Dennis Ritchie.
The C Character Set

Constants, Variables and Keywords


Types of C Constants

C constants can be divided into two major categories:


(a) Primary Constants
(b) Secondary Constants
These constants are further categorized as shown in Figure :
Rules for Constructing Integer Constants
(a) An integer constant must have at least one digit.
(b) It must not have a decimal point.
(c) It can be either positive or negative.
(d) If no sign precedes an integer constant it is assumed to be
positive.
(e) No commas or blanks are allowed within an integer constant.
(f) The allowable range for integer constants is -32768 to 32767.
Rules for Constructing Real Constants
Real constants are often called Floating Point constants. The real constants could be
written in two forms—Fractional form and Exponential form. Following rules must
be observed while constructing real constants expressed in fractional form:

(a) A real constant must have at least one digit.


(b) It must have a decimal point.
(c) It could be either positive or negative.
(d) Default sign is positive.
(e) No commas or blanks are allowed within a real constant.

Ex.: +325.34
426.0
-32.76
-48.5792
The part appearing before ‘e’ is called mantissa, whereas the part following ‘e’
is called exponent. Following rules must be observed while constructing real
constants expressed in exponential form:

(a) The mantissa part and the exponential part should be


separated by a letter e.
(b) The mantissa part may have a positive or negative sign.
(c) Default sign of mantissa part is positive.
(d) The exponent must have at least one digit, which must be a
positive or negative integer. Default sign is positive.
(e) Range of real constants expressed in exponential form is -3.4e38 to
3.4e38.

Ex.: +3.2e-5
4.1e8
-0.2e+3
-3.2e-5
Rules for Constructing Character Constants
(a) A character constant is a single alphabet, a single digit or a single special
symbol enclosed within single inverted commas. Both the inverted commas
should point to the left. For example, ’A’ is a valid character constant whereas
‘A’ is not.
(b)The maximum length of a character constant can be 1 character.
Ex.: 'A'
'I'
'5'
'='
Rules for Constructing Variable Names
(a)A variable name is any combination of 1 to 31 alphabets, digits or underscores. Some
compilers allow variable names whose length could be up to 247 characters. Still, it
would besafer to stick to the rule of 31 characters. Do not createunnecessarily long
variable names as it adds to your typing
effort.
(b)The first character in the variable name must be an alphabet or underscore.
(c)No commas or blanks are allowed within a variable name.
(d)No special symbol other than an underscore (as in gross_sal) can be used in a
variable name.
Ex.: si_int
m_hra
pop_e_89
C Keywords
The First C Program
#include <stdio.h> Receiving Input
main( ) #include <stdio.h>
{ main( )
int p, n ; {
float r, si ; int p, n ;
p = 1000 ; float r, si ;
n=3; printf ( "Enter values of p, n, r" ) ;
r = 8.5 ; scanf ( "%d %d %f", &p, &n, &r ) ;
/* formula for simple interest */ si = p * n * r / 100 ;
si = p * n * r / 100 ; printf ( "%f" , si ) ;
printf ( "%f" , si ) ; }
}
C Instructions
Three types of instructions in C:
(a)Type declaration instruction − To declare the type of variables used in a C
program.
(b)Arithmetic instruction − To perform arithmetic operations between
constants and variables.
(c)Control instruction − To control the sequence of execution of various
statements in a C program.

Some Algebraic and C Expression


Control Instructions in C
There are four types of control instructions in C. They are:
(a) Sequence Control Instruction
(b) Selection or Decision Control Instruction
(c) Repetition or Loop Control Instruction
(d) Case Control Instruction
Features of C
C is widely used in system programming. It has
some features.
 Portable/Machine independent
 Simple
 fast
 Extensible
 Memory Management
 Rich library
 pointers
 Recursion
Uses of C
Initially C was used in system development,
specifically to make the programs for
operating systems. Later it will used in
system applications. Here we have examples
that uses the C Languages as below.
Assignment:
The three primary constants and variable types in C are integer,
float and character.
A variable name can be of maximum 31 characters.
Do not use a keyword as a variable name.
An expression may contain any sequence of constants, variables
and operators.
Operators having equal precedence are evaluated using
associativity.
Left to right associativity means that the left operand of a operator
must be unambiguous whereas right to left
associativity means that the right operand of a operator must be
unambiguous.
Input/output in C can be achieved using scanf( ) and printf()
functions.

You might also like