SlideShare a Scribd company logo
Dharma Kumari Kalakheti (Bhandari)
Teaching Assistant-Sukuna Multiple Campus
Sundarharaincha-12
Morang Nepal
Province No.1
c -Programming
Program is a set of coded instructions that a computer can
understand to solve a problem or produce a desired result.
Two basic types of computer programs are (1) an operating
system, which provides the most fundamental instructions a
computer uses in its operations, and (2) an application
program, which runs on the operating system and does a
specific job such as word processing.
A computer can’t perform any work by itself. It must be fed with some
instructions by which it knows what to do. Collection of such instructions (i. e.
a set of coded instructions) is called a program.
 These instructions (Program/s) help the computer to know
what to do .
 Without programs, computers are useless and can do
nothing .
 Note that computer does not understand the instructions ( so
called programs) written in human language directly.
NOW, CAN YOU ANSWER THIS
QUESTION?
What is a program ?
Programming language
 We have known that computer can’t understand the
human language directly. It can only understand the
machine language (binary codes).
 Computer Users know only natural human language/s.
The communication between two parties whether they are
machines or human beings always need a common
language or terminology(words/terms)
 The language (prepared)used to communicate with the
computer is known as programming language. (It is
written in human language but in programming form- with certain codes-
following the fixed instructions). The programming language can be
understood by the programmers but the laymen may not
necessarily understand although the language is human.
 It (The programming language) is also not directly
understood by the computer. It needs language
processor.
 Then, the program prepared in the specific codes is
converted to the machine understandable form by any
conversion process.
 The person who writes programs is called a
programmer and the task of writing program is
programming.
Now, consider the following questions:
1. What is programming ?
2. What is a program ?
3. What does a programmer mean? or Who
is a programmer?
4. What is ‘programming language’ ?
1. Program – A collection of
sequential instructions given to
computer to carry out certain task.
2. Programming – The work/task of
writing a set of sequential
instructions is called programming.
3. Programmer – The person who
writes a set of instructions to a
computer.
4. The language used to communicate with
the computer is known as programming
language.
/* Display your name*/
#include <stdio.h>
#include <conio.h>
Int main()
{
Printf(“hello ! I am Ram”);
Getch();
}
1. Low level language
a) Machine level language.
b) Assembly level language.
2. High level language
a) Compilers
b) Interpreters
The C was developed at AT and T’s Bell Lab of the
USA in 1972. It was designed and written by a man
named Dennis Ritchie . C was derived from a
language known as BCPL which was developed at
the Massachusetts Institute of Technology in the late
1960s. C is a successor of BCPL language.
C is a very powerful and most popular high
level programming language. It is a structural
programming language. Popular operating
systems such as UNIX , LINUX ,MINIX and
many system and application programs are
written in C.
with feature of high level language and therefore it
is suitable for writing both system software and
application software. C is programming language
for academic purpose. For this reason many
universities have a course in C programming in
their curriculum . C has very typical syntax
which can later be used to learn other
languages.
Tips
 C was developed by Dennis Ritchie in 1972
at the Bell Telephone Laboratories in USA .
 C is a general-purpose programming
language.
 C is a high-level language that has the
advantages of readability, maintainability,
and portability.
 Programs written in C can be reused.
 C provides many programming languages,
such as Perl, C++, and Java, with basic
concepts and useful features.
 C is the ANSI standard programming
language.
By 1960 there ware a number of programming
languages. But almost all were used for
specific purpose only. For example ,
 FORTRAN (formulaTranslation) and COBOL(Common
Business Oriented) developed in 1960 with specific
use and specific purpose.
 General purpose language was developed in
1960Which is called ALGOL (Algorithmic Oriented
Language).
 ALGOL was too abstract (=unobservable )
and too general.
 Cambridge university developed a new
programming language in 1963 which was
called CPL(Combined Programming language).
 CPL was also too broad and had too many
features.
 Therefore, Martin Richard developed BCPL in 1967.
 BCPL was so less powerful and too much specific.
 Ken Thompson (at AT & T Bell Lab ) developed a
programming language called B in 1970..
 B was less specified and much powerful.
 Taking all the good and strong features of BCPL, CPL
and B, C programming language was developed by
Dennis Richie at AT & T’s Bell lab in 1972 for use
with the UNIX operating system.
 Readability: Programs written in C are easy to
read.
 Maintainability: Programs are easy to
maintain(= keep).
 Portability: Programs are easy to port across
different computer platforms.
 C is a structured (modular) programming
language
 C is a general-purpose (multipurpose)
Note: It is being used to develop operating
system, business application, text
processing, data-base applications, spread-
sheets, compilers etc. More than 70%
softwares are developed in C language
1. The main disadvantage of C, particularly for beginners, is its
conciseness (shortness/brevity). Brief statements may be written
to carry out complex computation.
2. C programs use the pointers extensively (heavily /a lot ).
3. It is difficult to read C programs. In other words, C often becomes
difficult to understand because it is written by professional
programmers .
4. The programmers tend to use tricks with pointer and other C
features to make the program small.
/* Display your name*/
#include <stdio.h>
#include <conio.h>
Int main()
{
Printf(“hello ! I am Ram”);
Getch();
}
Alphabets
Digits
Special symbol
Constants
Variables
Keywords
Instructions program
Steps in learning English language
alphabets words Sentences paragraph
Programming elements of C language
Basic elements of C programming language are
as follows:
1. Character set 2. keyword 3. variable
4. Operators 5. expression 6. statement
7.constants
Alphabets :-
A,a………….Z,z
Character sets are valid set of characters used in C
programming language.They can be considered as
the basic elements of the programming.They
include letters (alphabets), numbers (digits) and
special symbols.The valid character sets used in C
programming language
are given blow:
Special symbol :-
! * + “ ( = % ) ; / :
, ? & ! ‘ . [ ] { }

. | ~ ^ < > : “ “ ` $ #
(blank)
Digits:-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Compiler collects the valid characters set s to make
sensible tokens. So, it can be said that tokens are
collections of different characters, operators or
punctuators. The first job of the compiler is to test
the validity of these tokens there are six types of
tokens as prescribed by C
 Keyword
 Identifiers
 Constants
 String constants
 Operators
 Punctuators
Keywords are the reserved words used in the
program.That means they are defined in the C
compiler. Each key has a fixed meaning and that
cannot be changed by user, e.g,
int money
Here, int is a keyword
Key words are those words whose meaning is
already define by compiler.As ,c programming
language is case sensitive all keyword must be
written in lowercase.
They have special significance in C programs.
They may not be used in any other purposes.
For example, keywords cannot be used to
give the variable's names, function's name
etc .There are altogether 32 keywords in C
programming which are in the following
table:
auto break case char const continue default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while
Variable is an identifier whose value changes
time to time during program execution. Each
and every variables must be declared before it
is used . It is a memory location that can hold a
value of a certain data type. Programmers
cannot use any of the keywords as variable
names.
e.g.
Int a; (Here, ‘int’ is data type and ‘a’ is variable)
The syntax to declare a new variable is
a) first write the data type
b) then, give a valid variable identifier
as given in the following examples:
Int a ;
float total;
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,sum;
a=10;
b=5;
sum=a+b;
printf("sum=%d",sum);
getch();
}
 A variable name is any combination of 1 to
31 alphabets digits or underscores.
 First characters in the variable name must be
an alphabet or underscore.
 No commas or blanks are allowed within a
variable name.
 No special symbols other then an underscore
can be used in variable name.
A constant is an entity that doesn't change during
execution of the program. The constants are
also formed (made) with alphabets , numbers ,
etc . However , the constants do not change but
variables change. Consider the following table
with a variable and constants in the memory
cells:
A
5
A
10
C constants are of different types . The basic
types are as follows:
(a) Integer constants (b) real (floating –
point) constants, (c ) character constants
and (d)string constants.
All the integer values can be considered as intege
constants
Rule for constructing integer constant
An integer constant must have at least one digit.
It must not have a decimal point.
It can be either positive or negative.
If no sign precedes an integer constant, it is
assumed to be positive
No commas or blanks are allowed within an
integer constant.
All the numbers with fractional parts can be
considered as floating constants
Rule for constructing real /Floating-point constant
➢ A real constant must have at least one digit.
➢ It must have a decimal point.
➢ It could be either positive or negative.
➢ Default sign is positive.
➢ No commas or blanks are allowed within a real
constant.
Characters are also constants which are
single alphabets enclosed in single quotes.
➢ A character constant is a single alphabet, a
single digit or single special symbol
enclosed within the single inverted
commas. Both the inverted commas should
point to the left. For example ,’A’ is valid
character constant whereas ‘A’ is not.
➢ The maximum length of character
constant can be 1 character.
Collection of multiple character constants are
called string constants which are enclosed in
double quotes(i.e. “ Ram”, “Sita”, etc. )
 It must be formed with more than one
characters.
 It must be enclosed within double quotations.
 There should be no space between the
characters . But underscore can be used.
A data type in a programming
language is a set of data with
values(size) having predefined
characteristics such as
integers, floats and characters
etc . Storage representations
and data types differ form
machine to machine.
C supports a number of data types; if
they are not enough, programmers
can also define their own data types. C
supports three classes of data types:
 Primitive (or basic) data types – these are the
fundamental data types supported by the language. These
can be classified as integer types, floating point types and
character types.
 User defined data types – based on the fundamental data
types . Users can define their own data types. These
include type defined data types (using typedef keyword)
and enumerate types (using enum keyword).
 Derived data types – programmers can derive data types
such as arrays, structures, unions and pointers by
combining several data types together.
 Write a program to calculate total amount of (p)kept in
bank for (n) years at the rate of (r) simple interest per
annum.
 Write a program to read the radius of a sphere and compute
its surface area and volume.
 Write a program to read base and altitude of a triangle and
prints its area.
8. Write a program to calculate total amount of (p)kept in bank for (n) years at
the rate of (r) simple interest per annum.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float I,P,Total,T,R;
printf("Enter the Value of P = ");
scanf("%f",&P);
printf("Enter the Value of T= ");
scanf("%f",&T);
printf("Enter the Value of R= ");
scanf("%f",&R);
I=(P*T*R)/100;
Total=p+I;
printf("Interest= %.2f",I);
Printf(“ Total amount=%.2f”,total);
getch();
}
5. Write a program to read the radius of a sphere and compute its surface
area and volume.
#include<math.h>
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float A,V,r;
float PI=3.14;
printf("Enter the Value of Radious :");
scanf("%f",&r);
A=4*PI*pow(r,2);
V=4/3*PI*pow(r,3);
printf("Area :%.2fn",A);
printf("Volume :%.2f",V);
getch();
}
#include<stdio.h>
//#include<math.h>
#include<conio.h>
void main()
{
float r,a,v;
float pi=3.14;
printf("enter radius");
scanf("%f",&r);
a=4*pi*(r*r);
v=4*pi*(r*r*r)/3;
printf("Surface of Area =%.2fn and
Peremeter=%.2f",a,v);
getch();
}
3. Write a program to read base and
altitude of a triangle and prints its
area.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float A,B,H;
printf("Enter the Value of Altitude of a triangle H= ");
scanf("%f",&H);
printf("Enter the Value of Base of a triangle B= ");
scanf("%f",&B);
A=(B*H)/2;
printf("Area= %.2f",A);
getch();
}
11.Write a program to print a
format of flag of Nepal .
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("*n");
printf("* *n");
printf("*t*n");
printf("*tt*n");
printf("*ttt*n");
printf("*tttt*n");
printf("*ttt*n");
printf("*tt*n");
printf("*t*n");
printf("* *n");
printf("*n");
printf("*n");
printf("*n");
printf("* *n");
printf("*t*n");
printf("*tt*n");
printf("*ttt*n");
printf("*tttt*n");
printf("*ttt*n");
printf("*tt*n");
Data Type Size in
bits
Size in Byte
Char 8 1 Byte
Int 32 4/2Bytes
Float 32 4Bytes
Double 64 8 Bytes
Void 0 Without value (null)
Expressions can be built up from literals,
variables and operators ( special
symbols). The operators define how the
variables and literals in the expression
will be manipulated.
 . Data items upon which operation is performed
are called operands
x + y
operands
operator
 Assignment operator
 Arithmetic operators
 Relational operators
 Logical operators
 Bitwise operators
The assignment operator is the simple equal
sign (=). The assignment operator is used to
assign a value to a variable. The format of an
assignment statement is:
variable-name = expression;
a+=b (a=a+b)
a-=b (a=a-b)
a/=b (a=a+b)
a%=b ( a=a%b)
a*= b (a=a*b)
C supports five major operators and two
extended (shortcuts) operators
Operators Action
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo division
++ Increment (extended)
-- Decrement (extended)
#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c;
float d,e,f;
a=10;
b=3;
c=5;
d=20.5;
e=10.25;
f=3.5;
printf("a/b=%dt a/c=%dn", a/b,a/c);
printf("d/e=%ft d/f=%ft d/a=%f",d/e,d/f,d/a);
getch();
}
4.Write algorithm, flow chart and program to input length & breadth of a room and
calculate and print its area and perimeter.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int l,b,A,P;
printf("Enter the L");
scanf("%d",&l);
printf("Enter the B");
scanf("%d",&b);
A=l*b;
P=2*(l+b);
printf("%d,%d",A,P);
getch();
}
Relational operators are used to compare two similar
operands, and depending on their relation. Relation
operators compare their left hand side operand with their
right hand side operand for lesser than, greater than lesser
than or equal to, greater than or equal to, equal or not equal
to relations. The value of a relational expression is either
1(condition is true) or 0 (if condition is false). C support six
relational operators
operator Meaning
> Greater than
< Less than
<= Less than or equal to
>= Greater than or equal to
== Equal to
!= Not equal
#include <stdio.h>
#include <conio.h>
void main()
{ int a=13,b=32,c=14;
clrscr();
printf("a<b=t%dt a>b=t%d", a<b,a>b);
printf("na==ct %da<=ct%dta>=ct%d",a==c,a<=c,a>=c);
getch();
}
Example of Relational Operators
#include <stdio.h>
#include <conio.h>
void main()
{ int a=13,b=32,c=14;
clrscr();
printf("a<b=t%d",a<b);
printf("na==ct%d",a==c);
getch();
}
Logical Operators
&& AND
|| OR
! NOT
Logical operators are used to compare or evaluate logical and
relation expressions. The operands of these operator must
produce either 1 (true) or 0(false ). The whole result produced
by these operators is also either true or false. There are three
logical operators in c:
Cont…
a b a && b a||b !a !b
0 0 0 0 1 1
0 1 0 1 1 0
1 0 0 1 0 1
1 1 1 1 0 0
Try to answer these questions:
1. Why is “NOT” operator unary ?
1.
Bitwise Operators
They are also called low level operators. C supports six
bitwise operators and they are listed in table below.
Their precedence (priority) is lower than arithmetic,
relational and logical operators
Operator Action
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~ One’s complement
>> Right shift
<< Left shift
cont
Bitwise operators are used for manipulating data at bit
level. These operators are used for testing the bits , or
shifting them to the left or to the right . Bitwise
operators can be applied only one integer –type
operands and not to float or double. There are three
types of bitwise operators:
 Bitwise Logical operators
 Bitwise shift operators
 One’s complement operator
Bitwise Logical operators
Bitwise logical operators performs logical ANDing
between two operands . There are three logical bitwise
operators:
Bitwise AND (&)
Bitwise OR (|)
Bitwise Exclusive OR(^)
Bitwise AND(&): the result of ANDing opration is 1 if the
both the bit have a value of 1 ; otherwise it is 0. let us
consider two variable n1=60 and n2 =15. the binary
representations of these two variables are:
N1= 0000 0000 0011 1100
N2= 0000 0000 0000 1111
If we execute the statement,
N3=N1&N2
The result will be .
N3=0000 0000 0000 1100
Although the resulting bit pattern represents the decimal
number 12, there is no plain connection between the
decimal values of these variables
Bitwise OR(|): the result of ORing operation is 1 if
eihter of the bit have a value of 1 ; otherwise it is 0. let
us consider two variable n1=60 and n2 =15. the binary
representations of these two variables are:
N1= 0000 0000 0011 1100
N2= 0000 0000 0000 1111
If we execute the statement,
N3=N1|N2
The result will be .
N3=0000 0000 0011 1111
Again , although the resulting bit pattern represents the
decimal number 63, there is no plain connection
between the decimal values of these variables
Bitwise Exclusive XOR(^): the result of exclusive ORing
operation is 1 only if one of the bit have a value of 1;
otherwise it is 0. let us again consider the two
variables n1=60 and n2=15. if we execute the
statement,
N3=n1^n2;
Then the result will be
n1 0000 0000 0011 1100
n2 0000 0000 0000 1111
---------------------
0000 0000 0011 0011
Again , although the resulting bit pattern represents
the decimal number 53, there is no plain connection
between the decimal values of these variables .
#include <stdio.h>
#include <conio.h>
void main()
{
int n1=60,n2=15,AND,OR,XOR;
clrscr();
AND=n1&n2;
OR=n1|n2;
XOR=n1^n2;
printf("AND=%dn",AND);
printf("OR=%dn",OR);
printf("XOR=%dn",XOR);
getch();
}
Bitwise shift operators are used to move bit
patterns either to left or to the right. There
are two bitwise shift operators:
 Left shift (<<)
 Right shift (>>)
Left shift (<<): the left shift operation causes
the operand to be shifted to the left by some
bit positions. The general of left-shift
operation is -
Operand << n
The bits in the operand are shifted to the left by n positions. The
leftmost n bits in the original bit pattern will be lost and the
rightmost n bits empty positions will be filled with 0s. For
example if n1=60, than if we execute the statement,
n2=n1<<3;
The result is calculated as;
n1 0000 0011 1100
Shift1 0000 0111 1 000
Shift 2 0000 1111 0000
Shift 3 0001 1110 0000
Right shift (>>): the ritht shift operation causes the operand
to be shifted to the right by some bit positions. The general
of right-shift operation is -
Operand >> n
The bits in the operand are shifted to the right by n positions.
The leftmost n bits will be lost the empty leftmost n bits
positions will be filled 0s , if the operand an unsigned
integer . If the operation is assigned , then the operand is
machine dependent, for example if unsigned int n1=60,
then if we execute the statement,
N2=n1>>3;
The result is calculate as;
n1 0000 0000 0011 1100
Shift 1 0000 0000 00011110
Shift 2 0000 0000 0000 1111
Shift 3 0000 0000 0000 0111
The following example shows the operation of these two shift Bitwise perators:
#include <stdio.h>
#include <conio.h>
void main()
{
unsigned int n1=60,left,right;
clrscr();
left=n1<<3;
right=n1>>3;
printf("left=%d", left);
printf("right=%d",right);
getch();
}
Bitwise one’s compliment operator is a unary operator
which inverts all the bits presented by its operand. This
means that all 0s become 1s and all 1s become 0s. For
example , if n1=60 than if we execute the statement,
n2=~n1
Than the result is calculated as,
n1= 0011 1100
n2= 1100 0011
#include <stdio.h>
#include <conio.h>
void main()
{
unsigned int n1=60,n2=60,left,right;
clrscr();
left=n1<<3;
right=n1>>3;
n2=~n1;
printf("left=%d", left);
printf("right=%d",right);
printf("compliment=%d",n2);
getch();
}
Increment and decrement operators
C offers two unusual and unique operators ++ and
-- called increment and decrement operator
respectively. The use of these two operators will
results in the value of the variable being
incremented or decremented by unity. i=i+1 can be
written as i++ and j=j-1 can be written as j--. The
increment operators is used to increase the value of
an operand by 1; and the decrement operator is
used to decrease the value of an operand by 1.
they take only one operand, so called unary
operator. The syntax for the operator is.
++a a= a+1
a++ a= a+1
--a a= a-1
a-- a= a-1
The increment and decrement operators can be
used as postfix or prefix notations.
The operators can be place either before or after
the operand. If the operator is placed before the
variable (++I or --I) it is known as pre
incrementing or pre decrementing.
If the operator is placed after the variable
(I++ or I--) it is known as post incrementing or
post decrementing
Let us see an example to illustrate the use of increment
and decrement operator
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int a=10;
printf("ta=%dn",a);
printf("ta=%dn",++a);
printf("ta=%dn",a++);
printf("ta=%dn",a);
getch();
}
Output:
In this example, initially the value of a is 10. When ++a is displayed, the variable
a is first incremented by 1(i.e 11)and then displayed; so the result is 11. but
when a++ is displayed , the value of a is displayed first and then increment
By one. Thus, it shows 11 at this time but when displayed again, it shows 12.
#include <stdio.h>
#include <conio.h>
void main()
{
int num,a=5;
num=++a;
printf( "%d %d",num,a);
getch();
}
What will be output if you execute following c code?
void main()
{
int num,a=5; num=++a; printf( "%d %d",num,a);}
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int sum,d1,d2,d3,d4,d5,n,n1,n2,n3,n4;
printf("Enter the Value of Five Digit = ");
scanf("%d",&n);
n1=n;
d1=n1%10;
n1=n/10;
d2=n1%10;
n2=n1/10;
d3=n2%10;
n3=n2/10;
d4=n3%10;
n4=n3/10;
d5=n4%10;
sum=d1+d2+d3+d4+d5;
printf("sum= %d",sum);
getch();
}
//Write program to input 5 digit integer and
print sum of digit in it.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int sum,d1,d2,d3,d4,d5,n;
printf("Enter the Value of Five Digit = ");
scanf("%d",&n);
// n=n;
d1=n%10;
n=n/10;
d2=n%10;
n=n/10;
d3=n%10;
n=n/10;
d4=n%10;
n=n/10;
d5=n;
sum=d1+d2+d3+d4+d5;
printf("sum= %d",sum);
getch();
}
1. Unary (monadic): Require / take one
operand
2. Binary(dyadic) : Require /take two operands
3. Ternary : Require/take three operands
2. How many kinds of operators are there according to
the number of operands ? and what are they ?
An expression represents a single data item,
such as number or character.An expression
may be a single entity or combination of such
entities interconnected by one or more
operators.
c = a + b
a = c * b
a==b
a < b, etc.
A statement causes (gives instructions)
the computer to carry out some
action. There are five types of
statements, which are:
i) Expressional (simple ) Statement
ii) Compound Statement
iii) Control Statement
iv) Iterative Statement (for, while ,do …..while)
v) Jump statement( goto, continue, break, return)
An expression statement consists of an
expression followed by semi colon.
Example:
x = 3;
y = a+c;
printf (“Total = %f ", total);
A compound statement consists of(includes)
several individual expression statements
enclosed within a pair of braces ({ and }).
Example:
{
pi = 3. 141593;
circumference = 2.0 * pi * radius;
area = pi * radius * radius;
}
A control statement is used to create special program
features, such as logical test, loops and branches.
Example:
if (area < 12)
{
printf (“Area is small”);
}
printf (“Area is big”);
Do
{
Statement(s);
}
While (condition)
A variable is an entity that may
change. It is located in the
memory space.
Step 1: Start
Step 2: Input a and b.
Step 3: sum= a + b
Step 4: Print sum
Step 5: end
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:
An algorithm is the most commonly used programming
tool. An algorithm is a stepwise presentation of procedures
to perform specific task in the computer. In the algorithm ,
instructions are written in the sequential order to solve a
particular problem. Algorithm is written in simple English
language.
An algorithm is named after the 9th century mathematician,
“Abu Jafar Muhammad Ibn Al –knowarizmi of Bagdad (Iraq)
 We should prepare an algorithm by dividing the
problem into small modules
 There should be finite(fixed) number of steps in an
algorithm.
 The input has to be identified for the particular
problem.
 Required output has to be identified from the given
input.
 The steps written in the algorithm should be simple
and clear.
After writing algorithm, programmer makes flowchart to
represent that algorithm. Graphical(pictorial)
representation of sets of instructions is called
FLOWCHART.The first “flow chart” was introduced by
Frank Gilberth
.
Terminal indicates the beginning and end of the
program. It is of OVAL shape. Start or end is
written inside it……….
End
This symbol indicates input or
output function.This notation is
used to input data and to display
result.The shape of input/output
notation is PARALLELOGRAM.
This symbol is used to check the
condition of the program. This
symbol gives yes or no result.The
shape of this symbol is diamond.
 This symbol indicates the
function(information processing)
like calculations or movements.
It is rectangle in shape.
Connector is used to
join different parts of
the flow-chart.
Step 1: Start
Step 2: Input a and b.
Step 3: sum= a + b
Step 4: Print sum
Step 5: end
Start
Input a
and b
Sum= a+b
Print sum
Stop
Q. Write an algorithm and draw
flowchart to find the largest
numbers among two numbers.
Step1: Start
Step2: enter the three number
Step3: read the three number: a, b & c
Step4: if a>b and a>c , then print “a is
greatest”.
Step5: if b>a and b>c them print “b is greatest”
else print C is greatest
Step6: stop
.
START
Read numbers
a ,b ,c
Is a>b?
Is a>c ? Is b>c ?
PRINT a
as
greater
PRINT C
is greater
PRINT b
as
greater
STOP
YES
YES YES
NO
NO NO
.
start
Stop
Input P
Input T
Input R
Print S
S=(P*T*R)/100
Flowchart to find out simple interest.
 Example: Make an algorithm and then a flowchart
in detail as far as possible, for the tasks performed,
while making a phone call.
One of the possible algorithms might look like
this:
Step 1. (start)- Recall the phone number.
Step 2. Lift the Phone receiver
Step 3. Check for Dial tone?
If YES Go to Step 4
If No Put down the receiver
Go to Step 2
Step 4. Dial the phone number.
Step 5. Is the phone ringing?
If Yes Go to Step 6.
If No Put down the receiver
Go to Step 2
Step 6. Has the phone being picked up?
If Yes Talk with the other end.
Go to Step 8.
If No Go to Step 7.
Step 7. Has the bell stopped ringing?
If Yes Put down the receiver
Go to Step 2.
If No Go to Step 6
Step 8. Put down the receiver.
Stop
General symbols used in Flowchart
 Flowchart based upon the above algorithm is as follows:
START
READ Phone No.
Lift the Receiver
Is there dial tone?
Put down the receiver
Dial the Phone
No.
Is the phone
Ringing?
No
No
Has the phone
been picked?
Yes
Yes
Yes
Talk with other end
STOP
Has the bell
Stopped?
Put down the
receiver
No
No
Yes
Pseudo codes
When we are planning to write a program , we prepare
an algorithm and them a flowchart. Before coding the
program in editor , we prepare a code . It looks like a
program but it is not . Such a program like code is
called “pseudo-code”.
❑It is also called structured code .
❑ It is program independent construct.
Cont…
Look at the following example of the pseudo-code :
Input a, b
If a>b
g=a
Else
g=b
End if
Print “largest number is”,g
Examples – Algorithm & Flowchart
2. Develop an Algorithm to
read two numbers and
print the bigger number.
Convert it into
Flowchart.
Read two numbers N1 and N2
Is N1 > N2
YES Print N1
NO Print N2
Stop
START
Read N1, N2
Is N1 > N2?
PRINT N1 PRINT N2
STOP
YES
NO
 The title should be given to every flowchart.
 Operation should be written inside every
symbol of the flowchart.
 The language should be simple and easy to
understand for any programmers.
 The flow-line in the flowchart should won't
cross each other.

More Related Content

What's hot

Introduction to C Language
Introduction to C LanguageIntroduction to C Language
Introduction to C Language
Tarun Sharma
 
Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)
Shujaat Abbas
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
Akhilesh Maithani
 
C Language
C LanguageC Language
C Language
Aakash Singh
 
C Language
C LanguageC Language
C Language
Syed Zaid Irshad
 
Introduction to programming with c,
Introduction to programming with c,Introduction to programming with c,
Introduction to programming with c,
Hossain Md Shakhawat
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
Rokonuzzaman Rony
 
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)
Rohit Singh
 
Abc c program
Abc c programAbc c program
Abc c program
Dayakar Siddula
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
srmohan06
 
C language part 1
C language part  1C language part  1
C language part 1
PadmavathyK1
 
C programming presentation for university
C programming presentation for universityC programming presentation for university
C programming presentation for university
Sheikh Monirul Hasan
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
Akshay Ithape
 
Programming assignment help
Programming assignment helpProgramming assignment help
Programming assignment help
www.myassignmenthelp.net
 
C language
C languageC language
C language
marar hina
 
Features of c
Features of cFeatures of c
Features of c
Hitesh Kumar
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1
REHAN IJAZ
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languagesVarun Garg
 
C basics
C   basicsC   basics

What's hot (20)

Introduction to C Language
Introduction to C LanguageIntroduction to C Language
Introduction to C Language
 
Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)Introduction to C Language (By: Shujaat Abbas)
Introduction to C Language (By: Shujaat Abbas)
 
Introduction of c language
Introduction of c languageIntroduction of c language
Introduction of c language
 
C Language
C LanguageC Language
C Language
 
C Language
C LanguageC Language
C Language
 
Introduction to programming with c,
Introduction to programming with c,Introduction to programming with c,
Introduction to programming with c,
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
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)
 
Abc c program
Abc c programAbc c program
Abc c program
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Features of c language 1
Features of c language 1Features of c language 1
Features of c language 1
 
C language part 1
C language part  1C language part  1
C language part 1
 
C programming presentation for university
C programming presentation for universityC programming presentation for university
C programming presentation for university
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Programming assignment help
Programming assignment helpProgramming assignment help
Programming assignment help
 
C language
C languageC language
C language
 
Features of c
Features of cFeatures of c
Features of c
 
Programming Fundamentals lecture 1
Programming Fundamentals lecture 1Programming Fundamentals lecture 1
Programming Fundamentals lecture 1
 
Lect 1. introduction to programming languages
Lect 1. introduction to programming languagesLect 1. introduction to programming languages
Lect 1. introduction to programming languages
 
C basics
C   basicsC   basics
C basics
 

Similar to C programme presentation

unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshuunit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
GauravRawat830030
 
CS3251-_PIC
CS3251-_PICCS3251-_PIC
C Lang notes.ppt
C Lang notes.pptC Lang notes.ppt
C Lang notes.ppt
ShivanadhuniBhanuPra
 
C lecture notes new
C lecture notes newC lecture notes new
C lecture notes new
Kuntal Bhowmick
 
Unit 1
Unit 1Unit 1
Unit 1
TPLatchoumi
 
C.pdf
C.pdfC.pdf
Programming in C
Programming in CProgramming in C
Programming in C
Rvishnupriya2
 
Programming in c
Programming in cProgramming in c
Programming in c
vishnu973656
 
Introduction to C Programming Language.pptx
Introduction to C Programming Language.pptxIntroduction to C Programming Language.pptx
Introduction to C Programming Language.pptx
AnithaTAssistantProf
 
Introduction to Computer
Introduction to ComputerIntroduction to Computer
Introduction to Computer
zaheeriqbal41
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
Subramanyambharathis
 
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
ComedyTechnology
 
Intoduction to c language
Intoduction to c languageIntoduction to c language
Intoduction to c language
Student
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
Mukesh Tekwani
 
Ppt 1
Ppt 1Ppt 1
Software programming and development
Software programming and developmentSoftware programming and development
Software programming and development
Ali Raza
 
Introduction to programming c
Introduction to programming cIntroduction to programming c
Introduction to programming c
Md. Rakibuzzaman Khan Pathan
 
C Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYC Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYRajeshkumar Reddy
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)
aaravSingh41
 

Similar to C programme presentation (20)

Programming in c
Programming in cProgramming in c
Programming in c
 
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshuunit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
unit 1 programming in c ztgdawte efhgfhj ewnfbshyufh fsfyshu
 
CS3251-_PIC
CS3251-_PICCS3251-_PIC
CS3251-_PIC
 
C Lang notes.ppt
C Lang notes.pptC Lang notes.ppt
C Lang notes.ppt
 
C lecture notes new
C lecture notes newC lecture notes new
C lecture notes new
 
Unit 1
Unit 1Unit 1
Unit 1
 
C.pdf
C.pdfC.pdf
C.pdf
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Programming in c
Programming in cProgramming in c
Programming in c
 
Introduction to C Programming Language.pptx
Introduction to C Programming Language.pptxIntroduction to C Programming Language.pptx
Introduction to C Programming Language.pptx
 
Introduction to Computer
Introduction to ComputerIntroduction to Computer
Introduction to Computer
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
 
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
 
Intoduction to c language
Intoduction to c languageIntoduction to c language
Intoduction to c language
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
 
Ppt 1
Ppt 1Ppt 1
Ppt 1
 
Software programming and development
Software programming and developmentSoftware programming and development
Software programming and development
 
Introduction to programming c
Introduction to programming cIntroduction to programming c
Introduction to programming c
 
C Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDYC Unit 1 notes PREPARED BY MVB REDDY
C Unit 1 notes PREPARED BY MVB REDDY
 
C programming presentation(final)
C programming presentation(final)C programming presentation(final)
C programming presentation(final)
 

More from DharmaKumariBhandari

K map
K map K map
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,  De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
DharmaKumariBhandari
 
Loop's definition and practical code in C programming
Loop's definition and  practical code in C programming Loop's definition and  practical code in C programming
Loop's definition and practical code in C programming
DharmaKumariBhandari
 
Pointer
PointerPointer
About Array
About ArrayAbout Array
social prospective in Education
social prospective in Educationsocial prospective in Education
social prospective in Education
DharmaKumariBhandari
 
Array
ArrayArray

More from DharmaKumariBhandari (7)

K map
K map K map
K map
 
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,  De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
De Mornan Theory, Boolean Algebra, 7 logical get, truth table,
 
Loop's definition and practical code in C programming
Loop's definition and  practical code in C programming Loop's definition and  practical code in C programming
Loop's definition and practical code in C programming
 
Pointer
PointerPointer
Pointer
 
About Array
About ArrayAbout Array
About Array
 
social prospective in Education
social prospective in Educationsocial prospective in Education
social prospective in Education
 
Array
ArrayArray
Array
 

Recently uploaded

ÔN TẬP CỤM THÀNH NGỮ TIẾNG ANH CỰC HAY.docx
ÔN TẬP CỤM THÀNH NGỮ TIẾNG ANH CỰC HAY.docxÔN TẬP CỤM THÀNH NGỮ TIẾNG ANH CỰC HAY.docx
ÔN TẬP CỤM THÀNH NGỮ TIẾNG ANH CỰC HAY.docx
ngochaavk33a
 
Ethical_dilemmas_MDI_Gurgaon-Business Ethics Case 1.pptx
Ethical_dilemmas_MDI_Gurgaon-Business Ethics Case 1.pptxEthical_dilemmas_MDI_Gurgaon-Business Ethics Case 1.pptx
Ethical_dilemmas_MDI_Gurgaon-Business Ethics Case 1.pptx
TANMAYJAIN511570
 
CHUYÊN ĐỀ READING ÔN THI HSG THPT HAY.docx
CHUYÊN ĐỀ READING ÔN THI HSG THPT HAY.docxCHUYÊN ĐỀ READING ÔN THI HSG THPT HAY.docx
CHUYÊN ĐỀ READING ÔN THI HSG THPT HAY.docx
ngochaavk33a
 
UNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the NatureUNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the Nature
Chandrakant Divate
 
SOCIOLOGY PPT. SOCIAL SECURITY POWER POINT
SOCIOLOGY PPT. SOCIAL SECURITY POWER POINTSOCIOLOGY PPT. SOCIAL SECURITY POWER POINT
SOCIOLOGY PPT. SOCIAL SECURITY POWER POINT
ssuser8d5e2d1
 
Collocation thường gặp trong đề thi THPT Quốc gia.pdf
Collocation thường gặp trong đề thi THPT Quốc gia.pdfCollocation thường gặp trong đề thi THPT Quốc gia.pdf
Collocation thường gặp trong đề thi THPT Quốc gia.pdf
ngochaavk33a
 
Program Your Destiny eBook - Destiny University.pdf
Program Your Destiny eBook - Destiny University.pdfProgram Your Destiny eBook - Destiny University.pdf
Program Your Destiny eBook - Destiny University.pdf
Michael Herlache, MBA
 

Recently uploaded (7)

ÔN TẬP CỤM THÀNH NGỮ TIẾNG ANH CỰC HAY.docx
ÔN TẬP CỤM THÀNH NGỮ TIẾNG ANH CỰC HAY.docxÔN TẬP CỤM THÀNH NGỮ TIẾNG ANH CỰC HAY.docx
ÔN TẬP CỤM THÀNH NGỮ TIẾNG ANH CỰC HAY.docx
 
Ethical_dilemmas_MDI_Gurgaon-Business Ethics Case 1.pptx
Ethical_dilemmas_MDI_Gurgaon-Business Ethics Case 1.pptxEthical_dilemmas_MDI_Gurgaon-Business Ethics Case 1.pptx
Ethical_dilemmas_MDI_Gurgaon-Business Ethics Case 1.pptx
 
CHUYÊN ĐỀ READING ÔN THI HSG THPT HAY.docx
CHUYÊN ĐỀ READING ÔN THI HSG THPT HAY.docxCHUYÊN ĐỀ READING ÔN THI HSG THPT HAY.docx
CHUYÊN ĐỀ READING ÔN THI HSG THPT HAY.docx
 
UNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the NatureUNIVERSAL HUMAN VALUES- Harmony in the Nature
UNIVERSAL HUMAN VALUES- Harmony in the Nature
 
SOCIOLOGY PPT. SOCIAL SECURITY POWER POINT
SOCIOLOGY PPT. SOCIAL SECURITY POWER POINTSOCIOLOGY PPT. SOCIAL SECURITY POWER POINT
SOCIOLOGY PPT. SOCIAL SECURITY POWER POINT
 
Collocation thường gặp trong đề thi THPT Quốc gia.pdf
Collocation thường gặp trong đề thi THPT Quốc gia.pdfCollocation thường gặp trong đề thi THPT Quốc gia.pdf
Collocation thường gặp trong đề thi THPT Quốc gia.pdf
 
Program Your Destiny eBook - Destiny University.pdf
Program Your Destiny eBook - Destiny University.pdfProgram Your Destiny eBook - Destiny University.pdf
Program Your Destiny eBook - Destiny University.pdf
 

C programme presentation

  • 1. Dharma Kumari Kalakheti (Bhandari) Teaching Assistant-Sukuna Multiple Campus Sundarharaincha-12 Morang Nepal Province No.1
  • 2.
  • 4. Program is a set of coded instructions that a computer can understand to solve a problem or produce a desired result. Two basic types of computer programs are (1) an operating system, which provides the most fundamental instructions a computer uses in its operations, and (2) an application program, which runs on the operating system and does a specific job such as word processing. A computer can’t perform any work by itself. It must be fed with some instructions by which it knows what to do. Collection of such instructions (i. e. a set of coded instructions) is called a program.
  • 5.  These instructions (Program/s) help the computer to know what to do .  Without programs, computers are useless and can do nothing .  Note that computer does not understand the instructions ( so called programs) written in human language directly.
  • 6. NOW, CAN YOU ANSWER THIS QUESTION? What is a program ?
  • 7.
  • 8. Programming language  We have known that computer can’t understand the human language directly. It can only understand the machine language (binary codes).  Computer Users know only natural human language/s. The communication between two parties whether they are machines or human beings always need a common language or terminology(words/terms)
  • 9.  The language (prepared)used to communicate with the computer is known as programming language. (It is written in human language but in programming form- with certain codes- following the fixed instructions). The programming language can be understood by the programmers but the laymen may not necessarily understand although the language is human.  It (The programming language) is also not directly understood by the computer. It needs language processor.
  • 10.  Then, the program prepared in the specific codes is converted to the machine understandable form by any conversion process.  The person who writes programs is called a programmer and the task of writing program is programming.
  • 11.
  • 12. Now, consider the following questions: 1. What is programming ? 2. What is a program ? 3. What does a programmer mean? or Who is a programmer? 4. What is ‘programming language’ ?
  • 13. 1. Program – A collection of sequential instructions given to computer to carry out certain task. 2. Programming – The work/task of writing a set of sequential instructions is called programming. 3. Programmer – The person who writes a set of instructions to a computer.
  • 14. 4. The language used to communicate with the computer is known as programming language.
  • 15. /* Display your name*/ #include <stdio.h> #include <conio.h> Int main() { Printf(“hello ! I am Ram”); Getch(); }
  • 16. 1. Low level language a) Machine level language. b) Assembly level language. 2. High level language a) Compilers b) Interpreters
  • 17. The C was developed at AT and T’s Bell Lab of the USA in 1972. It was designed and written by a man named Dennis Ritchie . C was derived from a language known as BCPL which was developed at the Massachusetts Institute of Technology in the late 1960s. C is a successor of BCPL language.
  • 18. C is a very powerful and most popular high level programming language. It is a structural programming language. Popular operating systems such as UNIX , LINUX ,MINIX and many system and application programs are written in C.
  • 19. with feature of high level language and therefore it is suitable for writing both system software and application software. C is programming language for academic purpose. For this reason many universities have a course in C programming in their curriculum . C has very typical syntax which can later be used to learn other languages.
  • 20. Tips  C was developed by Dennis Ritchie in 1972 at the Bell Telephone Laboratories in USA .  C is a general-purpose programming language.  C is a high-level language that has the advantages of readability, maintainability, and portability.  Programs written in C can be reused.
  • 21.  C provides many programming languages, such as Perl, C++, and Java, with basic concepts and useful features.  C is the ANSI standard programming language.
  • 22. By 1960 there ware a number of programming languages. But almost all were used for specific purpose only. For example ,  FORTRAN (formulaTranslation) and COBOL(Common Business Oriented) developed in 1960 with specific use and specific purpose.  General purpose language was developed in 1960Which is called ALGOL (Algorithmic Oriented Language).  ALGOL was too abstract (=unobservable ) and too general.
  • 23.  Cambridge university developed a new programming language in 1963 which was called CPL(Combined Programming language).  CPL was also too broad and had too many features.  Therefore, Martin Richard developed BCPL in 1967.  BCPL was so less powerful and too much specific.  Ken Thompson (at AT & T Bell Lab ) developed a programming language called B in 1970..
  • 24.  B was less specified and much powerful.  Taking all the good and strong features of BCPL, CPL and B, C programming language was developed by Dennis Richie at AT & T’s Bell lab in 1972 for use with the UNIX operating system.
  • 25.  Readability: Programs written in C are easy to read.  Maintainability: Programs are easy to maintain(= keep).  Portability: Programs are easy to port across different computer platforms.  C is a structured (modular) programming language  C is a general-purpose (multipurpose)
  • 26. Note: It is being used to develop operating system, business application, text processing, data-base applications, spread- sheets, compilers etc. More than 70% softwares are developed in C language
  • 27. 1. The main disadvantage of C, particularly for beginners, is its conciseness (shortness/brevity). Brief statements may be written to carry out complex computation. 2. C programs use the pointers extensively (heavily /a lot ). 3. It is difficult to read C programs. In other words, C often becomes difficult to understand because it is written by professional programmers . 4. The programmers tend to use tricks with pointer and other C features to make the program small.
  • 28. /* Display your name*/ #include <stdio.h> #include <conio.h> Int main() { Printf(“hello ! I am Ram”); Getch(); }
  • 29. Alphabets Digits Special symbol Constants Variables Keywords Instructions program Steps in learning English language alphabets words Sentences paragraph
  • 30. Programming elements of C language Basic elements of C programming language are as follows: 1. Character set 2. keyword 3. variable 4. Operators 5. expression 6. statement 7.constants
  • 31. Alphabets :- A,a………….Z,z Character sets are valid set of characters used in C programming language.They can be considered as the basic elements of the programming.They include letters (alphabets), numbers (digits) and special symbols.The valid character sets used in C programming language are given blow:
  • 32. Special symbol :- ! * + “ ( = % ) ; / : , ? & ! ‘ . [ ] { } . | ~ ^ < > : “ “ ` $ # (blank) Digits:- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
  • 33. Compiler collects the valid characters set s to make sensible tokens. So, it can be said that tokens are collections of different characters, operators or punctuators. The first job of the compiler is to test the validity of these tokens there are six types of tokens as prescribed by C
  • 34.  Keyword  Identifiers  Constants  String constants  Operators  Punctuators
  • 35. Keywords are the reserved words used in the program.That means they are defined in the C compiler. Each key has a fixed meaning and that cannot be changed by user, e.g, int money Here, int is a keyword Key words are those words whose meaning is already define by compiler.As ,c programming language is case sensitive all keyword must be written in lowercase.
  • 36. They have special significance in C programs. They may not be used in any other purposes. For example, keywords cannot be used to give the variable's names, function's name etc .There are altogether 32 keywords in C programming which are in the following table:
  • 37. auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while
  • 38. Variable is an identifier whose value changes time to time during program execution. Each and every variables must be declared before it is used . It is a memory location that can hold a value of a certain data type. Programmers cannot use any of the keywords as variable names. e.g. Int a; (Here, ‘int’ is data type and ‘a’ is variable)
  • 39. The syntax to declare a new variable is a) first write the data type b) then, give a valid variable identifier as given in the following examples: Int a ; float total; #include <stdio.h> #include <conio.h> void main() { int a,b,sum; a=10; b=5; sum=a+b; printf("sum=%d",sum); getch(); }
  • 40.
  • 41.  A variable name is any combination of 1 to 31 alphabets digits or underscores.  First characters in the variable name must be an alphabet or underscore.  No commas or blanks are allowed within a variable name.  No special symbols other then an underscore can be used in variable name.
  • 42. A constant is an entity that doesn't change during execution of the program. The constants are also formed (made) with alphabets , numbers , etc . However , the constants do not change but variables change. Consider the following table with a variable and constants in the memory cells: A 5 A 10
  • 43. C constants are of different types . The basic types are as follows: (a) Integer constants (b) real (floating – point) constants, (c ) character constants and (d)string constants.
  • 44. All the integer values can be considered as intege constants Rule for constructing integer constant An integer constant must have at least one digit. It must not have a decimal point. It can be either positive or negative. If no sign precedes an integer constant, it is assumed to be positive No commas or blanks are allowed within an integer constant.
  • 45. All the numbers with fractional parts can be considered as floating constants Rule for constructing real /Floating-point constant ➢ A real constant must have at least one digit. ➢ It must have a decimal point. ➢ It could be either positive or negative. ➢ Default sign is positive. ➢ No commas or blanks are allowed within a real constant.
  • 46. Characters are also constants which are single alphabets enclosed in single quotes. ➢ A character constant is a single alphabet, a single digit or single special symbol enclosed within the single inverted commas. Both the inverted commas should point to the left. For example ,’A’ is valid character constant whereas ‘A’ is not. ➢ The maximum length of character constant can be 1 character.
  • 47. Collection of multiple character constants are called string constants which are enclosed in double quotes(i.e. “ Ram”, “Sita”, etc. )  It must be formed with more than one characters.  It must be enclosed within double quotations.  There should be no space between the characters . But underscore can be used.
  • 48. A data type in a programming language is a set of data with values(size) having predefined characteristics such as integers, floats and characters etc . Storage representations and data types differ form machine to machine.
  • 49. C supports a number of data types; if they are not enough, programmers can also define their own data types. C supports three classes of data types:
  • 50.  Primitive (or basic) data types – these are the fundamental data types supported by the language. These can be classified as integer types, floating point types and character types.  User defined data types – based on the fundamental data types . Users can define their own data types. These include type defined data types (using typedef keyword) and enumerate types (using enum keyword).  Derived data types – programmers can derive data types such as arrays, structures, unions and pointers by combining several data types together.
  • 51.  Write a program to calculate total amount of (p)kept in bank for (n) years at the rate of (r) simple interest per annum.  Write a program to read the radius of a sphere and compute its surface area and volume.  Write a program to read base and altitude of a triangle and prints its area.
  • 52. 8. Write a program to calculate total amount of (p)kept in bank for (n) years at the rate of (r) simple interest per annum. #include<stdio.h> #include<conio.h> void main() { clrscr(); float I,P,Total,T,R; printf("Enter the Value of P = "); scanf("%f",&P); printf("Enter the Value of T= "); scanf("%f",&T); printf("Enter the Value of R= "); scanf("%f",&R); I=(P*T*R)/100; Total=p+I; printf("Interest= %.2f",I); Printf(“ Total amount=%.2f”,total); getch(); }
  • 53. 5. Write a program to read the radius of a sphere and compute its surface area and volume. #include<math.h> #include<stdio.h> #include<conio.h> void main() { clrscr(); float A,V,r; float PI=3.14; printf("Enter the Value of Radious :"); scanf("%f",&r); A=4*PI*pow(r,2); V=4/3*PI*pow(r,3); printf("Area :%.2fn",A); printf("Volume :%.2f",V); getch(); }
  • 54. #include<stdio.h> //#include<math.h> #include<conio.h> void main() { float r,a,v; float pi=3.14; printf("enter radius"); scanf("%f",&r); a=4*pi*(r*r); v=4*pi*(r*r*r)/3; printf("Surface of Area =%.2fn and Peremeter=%.2f",a,v); getch(); }
  • 55. 3. Write a program to read base and altitude of a triangle and prints its area. #include<stdio.h> #include<conio.h> void main() { clrscr(); float A,B,H; printf("Enter the Value of Altitude of a triangle H= "); scanf("%f",&H); printf("Enter the Value of Base of a triangle B= "); scanf("%f",&B); A=(B*H)/2; printf("Area= %.2f",A); getch(); }
  • 56. 11.Write a program to print a format of flag of Nepal . #include<stdio.h> #include<conio.h> void main() { clrscr(); printf("*n"); printf("* *n"); printf("*t*n"); printf("*tt*n"); printf("*ttt*n"); printf("*tttt*n"); printf("*ttt*n"); printf("*tt*n"); printf("*t*n"); printf("* *n"); printf("*n"); printf("*n"); printf("*n"); printf("* *n"); printf("*t*n"); printf("*tt*n"); printf("*ttt*n"); printf("*tttt*n"); printf("*ttt*n"); printf("*tt*n");
  • 57. Data Type Size in bits Size in Byte Char 8 1 Byte Int 32 4/2Bytes Float 32 4Bytes Double 64 8 Bytes Void 0 Without value (null)
  • 58. Expressions can be built up from literals, variables and operators ( special symbols). The operators define how the variables and literals in the expression will be manipulated.  . Data items upon which operation is performed are called operands x + y operands operator
  • 59.  Assignment operator  Arithmetic operators  Relational operators  Logical operators  Bitwise operators
  • 60. The assignment operator is the simple equal sign (=). The assignment operator is used to assign a value to a variable. The format of an assignment statement is: variable-name = expression; a+=b (a=a+b) a-=b (a=a-b) a/=b (a=a+b) a%=b ( a=a%b) a*= b (a=a*b)
  • 61. C supports five major operators and two extended (shortcuts) operators
  • 62. Operators Action + Addition - Subtraction * Multiplication / Division % Modulo division ++ Increment (extended) -- Decrement (extended)
  • 63. #include <stdio.h> #include <conio.h> void main() { int a,b,c; float d,e,f; a=10; b=3; c=5; d=20.5; e=10.25; f=3.5; printf("a/b=%dt a/c=%dn", a/b,a/c); printf("d/e=%ft d/f=%ft d/a=%f",d/e,d/f,d/a); getch(); }
  • 64. 4.Write algorithm, flow chart and program to input length & breadth of a room and calculate and print its area and perimeter. #include<stdio.h> #include<conio.h> void main() { clrscr(); int l,b,A,P; printf("Enter the L"); scanf("%d",&l); printf("Enter the B"); scanf("%d",&b); A=l*b; P=2*(l+b); printf("%d,%d",A,P); getch(); }
  • 65. Relational operators are used to compare two similar operands, and depending on their relation. Relation operators compare their left hand side operand with their right hand side operand for lesser than, greater than lesser than or equal to, greater than or equal to, equal or not equal to relations. The value of a relational expression is either 1(condition is true) or 0 (if condition is false). C support six relational operators
  • 66. operator Meaning > Greater than < Less than <= Less than or equal to >= Greater than or equal to == Equal to != Not equal
  • 67. #include <stdio.h> #include <conio.h> void main() { int a=13,b=32,c=14; clrscr(); printf("a<b=t%dt a>b=t%d", a<b,a>b); printf("na==ct %da<=ct%dta>=ct%d",a==c,a<=c,a>=c); getch(); } Example of Relational Operators #include <stdio.h> #include <conio.h> void main() { int a=13,b=32,c=14; clrscr(); printf("a<b=t%d",a<b); printf("na==ct%d",a==c); getch(); }
  • 68. Logical Operators && AND || OR ! NOT Logical operators are used to compare or evaluate logical and relation expressions. The operands of these operator must produce either 1 (true) or 0(false ). The whole result produced by these operators is also either true or false. There are three logical operators in c:
  • 69. Cont… a b a && b a||b !a !b 0 0 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 1 1 1 1 1 0 0
  • 70. Try to answer these questions: 1. Why is “NOT” operator unary ? 1.
  • 71. Bitwise Operators They are also called low level operators. C supports six bitwise operators and they are listed in table below. Their precedence (priority) is lower than arithmetic, relational and logical operators Operator Action & Bitwise AND | Bitwise OR ^ Bitwise XOR ~ One’s complement >> Right shift << Left shift
  • 72. cont Bitwise operators are used for manipulating data at bit level. These operators are used for testing the bits , or shifting them to the left or to the right . Bitwise operators can be applied only one integer –type operands and not to float or double. There are three types of bitwise operators:  Bitwise Logical operators  Bitwise shift operators  One’s complement operator
  • 73. Bitwise Logical operators Bitwise logical operators performs logical ANDing between two operands . There are three logical bitwise operators: Bitwise AND (&) Bitwise OR (|) Bitwise Exclusive OR(^)
  • 74. Bitwise AND(&): the result of ANDing opration is 1 if the both the bit have a value of 1 ; otherwise it is 0. let us consider two variable n1=60 and n2 =15. the binary representations of these two variables are: N1= 0000 0000 0011 1100 N2= 0000 0000 0000 1111 If we execute the statement, N3=N1&N2 The result will be . N3=0000 0000 0000 1100 Although the resulting bit pattern represents the decimal number 12, there is no plain connection between the decimal values of these variables
  • 75. Bitwise OR(|): the result of ORing operation is 1 if eihter of the bit have a value of 1 ; otherwise it is 0. let us consider two variable n1=60 and n2 =15. the binary representations of these two variables are: N1= 0000 0000 0011 1100 N2= 0000 0000 0000 1111 If we execute the statement, N3=N1|N2 The result will be . N3=0000 0000 0011 1111 Again , although the resulting bit pattern represents the decimal number 63, there is no plain connection between the decimal values of these variables
  • 76. Bitwise Exclusive XOR(^): the result of exclusive ORing operation is 1 only if one of the bit have a value of 1; otherwise it is 0. let us again consider the two variables n1=60 and n2=15. if we execute the statement, N3=n1^n2; Then the result will be n1 0000 0000 0011 1100 n2 0000 0000 0000 1111 --------------------- 0000 0000 0011 0011 Again , although the resulting bit pattern represents the decimal number 53, there is no plain connection between the decimal values of these variables .
  • 77. #include <stdio.h> #include <conio.h> void main() { int n1=60,n2=15,AND,OR,XOR; clrscr(); AND=n1&n2; OR=n1|n2; XOR=n1^n2; printf("AND=%dn",AND); printf("OR=%dn",OR); printf("XOR=%dn",XOR); getch(); }
  • 78. Bitwise shift operators are used to move bit patterns either to left or to the right. There are two bitwise shift operators:  Left shift (<<)  Right shift (>>) Left shift (<<): the left shift operation causes the operand to be shifted to the left by some bit positions. The general of left-shift operation is - Operand << n
  • 79. The bits in the operand are shifted to the left by n positions. The leftmost n bits in the original bit pattern will be lost and the rightmost n bits empty positions will be filled with 0s. For example if n1=60, than if we execute the statement, n2=n1<<3; The result is calculated as; n1 0000 0011 1100 Shift1 0000 0111 1 000 Shift 2 0000 1111 0000 Shift 3 0001 1110 0000
  • 80. Right shift (>>): the ritht shift operation causes the operand to be shifted to the right by some bit positions. The general of right-shift operation is - Operand >> n The bits in the operand are shifted to the right by n positions. The leftmost n bits will be lost the empty leftmost n bits positions will be filled 0s , if the operand an unsigned integer . If the operation is assigned , then the operand is machine dependent, for example if unsigned int n1=60, then if we execute the statement, N2=n1>>3;
  • 81. The result is calculate as; n1 0000 0000 0011 1100 Shift 1 0000 0000 00011110 Shift 2 0000 0000 0000 1111 Shift 3 0000 0000 0000 0111 The following example shows the operation of these two shift Bitwise perators: #include <stdio.h> #include <conio.h> void main() { unsigned int n1=60,left,right; clrscr(); left=n1<<3; right=n1>>3; printf("left=%d", left); printf("right=%d",right); getch(); }
  • 82. Bitwise one’s compliment operator is a unary operator which inverts all the bits presented by its operand. This means that all 0s become 1s and all 1s become 0s. For example , if n1=60 than if we execute the statement, n2=~n1 Than the result is calculated as, n1= 0011 1100 n2= 1100 0011
  • 83. #include <stdio.h> #include <conio.h> void main() { unsigned int n1=60,n2=60,left,right; clrscr(); left=n1<<3; right=n1>>3; n2=~n1; printf("left=%d", left); printf("right=%d",right); printf("compliment=%d",n2); getch(); }
  • 84. Increment and decrement operators C offers two unusual and unique operators ++ and -- called increment and decrement operator respectively. The use of these two operators will results in the value of the variable being incremented or decremented by unity. i=i+1 can be written as i++ and j=j-1 can be written as j--. The increment operators is used to increase the value of an operand by 1; and the decrement operator is used to decrease the value of an operand by 1. they take only one operand, so called unary operator. The syntax for the operator is.
  • 85. ++a a= a+1 a++ a= a+1 --a a= a-1 a-- a= a-1 The increment and decrement operators can be used as postfix or prefix notations. The operators can be place either before or after the operand. If the operator is placed before the variable (++I or --I) it is known as pre incrementing or pre decrementing. If the operator is placed after the variable (I++ or I--) it is known as post incrementing or post decrementing
  • 86.
  • 87. Let us see an example to illustrate the use of increment and decrement operator #include <stdio.h> #include <conio.h> void main() { clrscr(); int a=10; printf("ta=%dn",a); printf("ta=%dn",++a); printf("ta=%dn",a++); printf("ta=%dn",a); getch(); } Output: In this example, initially the value of a is 10. When ++a is displayed, the variable a is first incremented by 1(i.e 11)and then displayed; so the result is 11. but when a++ is displayed , the value of a is displayed first and then increment By one. Thus, it shows 11 at this time but when displayed again, it shows 12.
  • 88. #include <stdio.h> #include <conio.h> void main() { int num,a=5; num=++a; printf( "%d %d",num,a); getch(); } What will be output if you execute following c code? void main() { int num,a=5; num=++a; printf( "%d %d",num,a);}
  • 89. #include<stdio.h> #include<conio.h> void main() { clrscr(); int sum,d1,d2,d3,d4,d5,n,n1,n2,n3,n4; printf("Enter the Value of Five Digit = "); scanf("%d",&n); n1=n; d1=n1%10; n1=n/10; d2=n1%10; n2=n1/10; d3=n2%10; n3=n2/10; d4=n3%10; n4=n3/10; d5=n4%10; sum=d1+d2+d3+d4+d5; printf("sum= %d",sum); getch(); } //Write program to input 5 digit integer and print sum of digit in it.
  • 90. #include<stdio.h> #include<conio.h> void main() { clrscr(); int sum,d1,d2,d3,d4,d5,n; printf("Enter the Value of Five Digit = "); scanf("%d",&n); // n=n; d1=n%10; n=n/10; d2=n%10; n=n/10; d3=n%10; n=n/10; d4=n%10; n=n/10; d5=n; sum=d1+d2+d3+d4+d5; printf("sum= %d",sum); getch(); }
  • 91. 1. Unary (monadic): Require / take one operand 2. Binary(dyadic) : Require /take two operands 3. Ternary : Require/take three operands
  • 92. 2. How many kinds of operators are there according to the number of operands ? and what are they ?
  • 93. An expression represents a single data item, such as number or character.An expression may be a single entity or combination of such entities interconnected by one or more operators. c = a + b a = c * b a==b a < b, etc.
  • 94. A statement causes (gives instructions) the computer to carry out some action. There are five types of statements, which are: i) Expressional (simple ) Statement ii) Compound Statement iii) Control Statement iv) Iterative Statement (for, while ,do …..while) v) Jump statement( goto, continue, break, return)
  • 95. An expression statement consists of an expression followed by semi colon. Example: x = 3; y = a+c; printf (“Total = %f ", total);
  • 96. A compound statement consists of(includes) several individual expression statements enclosed within a pair of braces ({ and }). Example: { pi = 3. 141593; circumference = 2.0 * pi * radius; area = pi * radius * radius; }
  • 97. A control statement is used to create special program features, such as logical test, loops and branches. Example: if (area < 12) { printf (“Area is small”); } printf (“Area is big”);
  • 99. A variable is an entity that may change. It is located in the memory space.
  • 100. Step 1: Start Step 2: Input a and b. Step 3: sum= a + b Step 4: Print sum Step 5: end
  • 101. Step 1: Step 2: Step 3: Step 4: Step 5:
  • 102. An algorithm is the most commonly used programming tool. An algorithm is a stepwise presentation of procedures to perform specific task in the computer. In the algorithm , instructions are written in the sequential order to solve a particular problem. Algorithm is written in simple English language. An algorithm is named after the 9th century mathematician, “Abu Jafar Muhammad Ibn Al –knowarizmi of Bagdad (Iraq)
  • 103.  We should prepare an algorithm by dividing the problem into small modules  There should be finite(fixed) number of steps in an algorithm.  The input has to be identified for the particular problem.  Required output has to be identified from the given input.  The steps written in the algorithm should be simple and clear.
  • 104. After writing algorithm, programmer makes flowchart to represent that algorithm. Graphical(pictorial) representation of sets of instructions is called FLOWCHART.The first “flow chart” was introduced by Frank Gilberth
  • 105.
  • 106.
  • 107.
  • 108. .
  • 109. Terminal indicates the beginning and end of the program. It is of OVAL shape. Start or end is written inside it………. End
  • 110. This symbol indicates input or output function.This notation is used to input data and to display result.The shape of input/output notation is PARALLELOGRAM.
  • 111. This symbol is used to check the condition of the program. This symbol gives yes or no result.The shape of this symbol is diamond.
  • 112.
  • 113.  This symbol indicates the function(information processing) like calculations or movements. It is rectangle in shape.
  • 114. Connector is used to join different parts of the flow-chart.
  • 115. Step 1: Start Step 2: Input a and b. Step 3: sum= a + b Step 4: Print sum Step 5: end
  • 116. Start Input a and b Sum= a+b Print sum Stop
  • 117. Q. Write an algorithm and draw flowchart to find the largest numbers among two numbers.
  • 118. Step1: Start Step2: enter the three number Step3: read the three number: a, b & c Step4: if a>b and a>c , then print “a is greatest”. Step5: if b>a and b>c them print “b is greatest” else print C is greatest Step6: stop
  • 119. . START Read numbers a ,b ,c Is a>b? Is a>c ? Is b>c ? PRINT a as greater PRINT C is greater PRINT b as greater STOP YES YES YES NO NO NO
  • 120. . start Stop Input P Input T Input R Print S S=(P*T*R)/100 Flowchart to find out simple interest.
  • 121.  Example: Make an algorithm and then a flowchart in detail as far as possible, for the tasks performed, while making a phone call. One of the possible algorithms might look like this:
  • 122. Step 1. (start)- Recall the phone number. Step 2. Lift the Phone receiver Step 3. Check for Dial tone? If YES Go to Step 4 If No Put down the receiver Go to Step 2 Step 4. Dial the phone number. Step 5. Is the phone ringing? If Yes Go to Step 6. If No Put down the receiver Go to Step 2 Step 6. Has the phone being picked up? If Yes Talk with the other end. Go to Step 8. If No Go to Step 7. Step 7. Has the bell stopped ringing? If Yes Put down the receiver Go to Step 2. If No Go to Step 6 Step 8. Put down the receiver. Stop
  • 123. General symbols used in Flowchart  Flowchart based upon the above algorithm is as follows: START READ Phone No. Lift the Receiver Is there dial tone? Put down the receiver Dial the Phone No. Is the phone Ringing? No No Has the phone been picked? Yes Yes Yes Talk with other end STOP Has the bell Stopped? Put down the receiver No No Yes
  • 124. Pseudo codes When we are planning to write a program , we prepare an algorithm and them a flowchart. Before coding the program in editor , we prepare a code . It looks like a program but it is not . Such a program like code is called “pseudo-code”. ❑It is also called structured code . ❑ It is program independent construct.
  • 125. Cont… Look at the following example of the pseudo-code : Input a, b If a>b g=a Else g=b End if Print “largest number is”,g
  • 126. Examples – Algorithm & Flowchart 2. Develop an Algorithm to read two numbers and print the bigger number. Convert it into Flowchart. Read two numbers N1 and N2 Is N1 > N2 YES Print N1 NO Print N2 Stop START Read N1, N2 Is N1 > N2? PRINT N1 PRINT N2 STOP YES NO
  • 127.  The title should be given to every flowchart.  Operation should be written inside every symbol of the flowchart.  The language should be simple and easy to understand for any programmers.  The flow-line in the flowchart should won't cross each other.