0% found this document useful (0 votes)
23 views30 pages

Basic Programing Constructs

Uploaded by

demonsoul96yt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views30 pages

Basic Programing Constructs

Uploaded by

demonsoul96yt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

File Downloaded From www.Bustudymate.

in

SUBJECT: PROBLEM SOLVING TECHNIQUES


USING C
SEMESTER: I SEMESTER
COURSE: BCA
SUBJECT TEACHER: Dr. K.Chitra,
Assistant Professor,
Department of Computer Science

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Basic programing constructs

Chapter -2

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

• There are 3 basic programming constructs


sequential
selection
Iteration

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Sequential Construct
In a sequential construct , program statements
are executed one after another.
Input statement
Assignment statement
Output statement

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Selection construct
• It is also known as conditional construct. It is
used to indicate decision in program.
• There are different kinds of selection constructs.
They are
simple if
if…else
if…else if
nested if
Switch statement
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in

Iteration constructor
• Some of the statements have to be executed
repeatedly, we can use repetition construct to
perform many iterations.
• Conditional looping
• Unconditional looping

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

• Conditional looping
Many programs requires that a group of
instructions be executed repeatedly until the logical
condition has been satisfied.
(E-x) while , do..while
• Unconditional looping
Execution of a group of consecutive instructions is
repeated some specified number of times.
(E-x ) for statement

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in
Chapter-3 overview of c

• C language is developed from BCPL (Basic


combined Programming Language).
• It was developed by Dennis Ritchie in 1972.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Importance of c
• It is robust.
robustness is the ability of a computer system to
cope with errors during execution.
• C has the advantage of assembly language
programming like bit manipulation and features
of high level language programming like
debugging.
• C is called as middle level language since it
combines low level language and high level
language.
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in

• It is suited for writing system software and


application software.
• It is platform independent and highly portable.
• C is a structured programing language. Program is
divided into so many modules.
• C consists of variety of data types and powerful
operators.
• C provides manipulation of internal processor
registers.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Applications of c
• Compilers
• Loaders
• Linkers
• Interpreters
• Operating system
• Database Management system
• Spread sheets

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Basic structure of C program


• Documentation section (comments)
• Preprocessor section (Header file)
• Definition section (Defining symbolic constants)
• Global Declaration section (global variables
declared)
• Main()
• {
• Declaration part (variable declaration)
• Executable part (statements in c)
• }
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in

• Subroutine section
f1()
f2()
.
.
fn()

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Documentation section
• This section consists of set of comment lines
starting with /* and ends with */
• This section helps the users to understand the
program.
• This section is optional and are not executed
by compiler.
E-x
/* To add two numbers */
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in

Preprocessor section
• This section contains header files which begins
with a #symbol and are extended with .h
• This section is used to include the header file.
E-x
#include <stdio.h>
#include <math.h>

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Definition section
• Symbolic constants are included using #define
e-x

#define pi 3.14

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Global Declaration section


• This section is used to define the variables
that would be used in more than one
function.
• This section should be declared before main()
function.
• E-x
int a;
main()
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in

main() function
• All c programs must contain main() function.
• It denotes the starting of the program.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Braces
• Execution of the program begins at the
opening brace { and ends at its closing brace.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Declaration part
• This part is used to declare all the variables
used in executable part.
• The syntax for declaration is
datatype list of variables;
E-x
int a,b;
float b,d;

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Executable part
• This part of the program consists of a set of
executable statements.
• Every statement in the declaration part and
executable part ended with ;
e-x
scanf %d%d ,&a,&b);
C=a+b;
printf %d , );
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in

Subroutine
• This section is optional and consists of all the user-
defined functions.
E-x
Function1()
{
Printf hello world ;
}
Function2()
{
Printf wel o e to the world ;
}
File Downloaded From www.Bustudymate.in
File Downloaded From www.Bustudymate.in

Example program
/* program to find circumference of the circle */
#include <stdio.h>
#define pi 3.14
main()
{
float circum,r;
Scanf %f ,&r);
circum=2*pi*r;
printf %f ,circum);
}

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Executing a c program
• Creation of program
• Compilation of a program
• Linking of a program
• Executing the program

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Creation of program
• Programs should be written in C editor.
• After typing the program ,save the program
with extension .c

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Compilation of a program
• The source program should be compiled by
using c compiler.
• If any syntax errors in a source program, then
compiler checks for it.
• Once all the errors are corrected, the compiler
converts the source program into object
program.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Linking the program


• All the library files are linked to the main
program.

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Executing the program


• After compilation and linking, the executable
o je t ode will e loaded i the o puter’s
main memory and the program is executed

File Downloaded From www.Bustudymate.in


File Downloaded From www.Bustudymate.in

Programming style
• All the statements should be written in lower
case letters.
• The programmer can write the statement
anywhere between two braces.
• The opening and closing braces should be
balanced.
• Use comment line whenever necessary.

File Downloaded From www.Bustudymate.in

You might also like