Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 49

Programming Methodology Using C

Unit-I
Programming Language Concepts
• What is a programming language?
• Why are there so many programming languages?
• What are the types of programming languages?
• Does the world need new languages?
What is a programming language?
Programming Language is

• A programming language is a set of rules that provides a way of


telling a computer what operations to perform.
• A means of communicating between programmers.
• A means of controlling computerized devices.
• A programming language is a set of rules for communicating an
algorithm
• It provides a linguistic framework for describing computations.
• A programming language is a notational system for describing
computation in a machine-readable and human-readable form.
• A programming language is a tool for developing executable models for
a class of problem domains.
English VS Programming Langugage
English Programming

English is a natural language. It has words, symbols A programming language also has words, symbols and
and grammatical rules. rules of grammar.

The grammatical rules are called syntax. Each programming language has a different set of
syntax rules.
Why So Many Programming languages
As there are various languages to speak similarly different
programming languages are designed for different types of programs.
Types of Programming Language
• Programs written in high-level languages are translated into assembly
language or machine language by a compiler.
• Assembly language programs are translated into machine language by
a program called an assembler.
High Level Language
• A high-level language is a programming language such as
C, FORTRAN, or Pascal that enables a programmer to write
programs that are more or less independent of a particular
type of computer.
• Such languages are considered high-level because they are
closer to human languages.
Compiler
We will discuss:

 What is Program?

 What is Computer Programming?

 Generations of Computer Programming.

 Algorithm
Program
• A program is a set of instructions following the rules of
the chosen language.

• Without programs, computers are useless.

• A program is like a recipe.


• It contains a list of ingredients (called variables) and a list
of directions (called statements) that tell the computer
what to do with the variables.
Contd..

• Program is in human readable form need to convert into


machine language so computer can understand the
instruction.

• The conversion can be done using two ways:


• Compile the program (Compiler)
• Interpret the program(Interpreter)
Computer Programming
• Computer programming is the process of writing, testing,
debugging/troubleshooting, and maintaining the source code of
computer programs.
• This source code is written in any programming language like C, C++,
JAVA, Perl etc.
Generations of Programming
Language
Contd..
• First Generation Languages : These are low-level
languages like machine language.

• Second Generation Languages : These are low-level


assembly languages used in kernels and hardware drives.

• Third Generation Languages : These are high-level


languages like C, C++, Java, Visual Basic and JavaScript.
Contd..
• Fourth Generation Languages : These are languages
that consist of statements, similar to statements in the
human language. These are used mainly in database
programming and scripting.
Example of these languages include
• Perl
• Python
• Ruby
• SQL
• MATLAB (Matrix Laboratory)
Contd..
• Fifth Generation Languages : These are the
programming languages that have visual tools to develop
a program.
Examples of fifth generation language include
Mercury, and Prolog.

NOTE:
- The first two generations are called low level
languages. The next three generations are called
high level languages.
POLL
Q. How many computer programming generations we
studied?
a)1
b)2
c)3
d)4
e)5
Algorithm
Programming is the process of taking an algorithm.

Now question is what is an algorithm?


•Algorithm is defined as “ the finite set of steps, which
provide a chain of action for solving a problem”
•It is step by step solution to given problem.
Steps to create an Algorithm
1. Identify the Inputs
What data do I need?
How will I get the data?
In what format will the data be?

2. Identify the Outputs


What outputs do I need to return to the user?
What format should the outputs take?
Contd..
3. Identify the Processes
How can I manipulate data to produce
meaningful results?
Data vs. Information

4. Break the Solution to steps


By breaking the solution to the steps we can
easily understand the logic of program
POLL
Q. C programming language comes under which
generation?
a)5
b)4
c)3
d)2
e)1
Simple Example of an Algorithm
To establish a telephone communication
• Step 1: Dial a phone number
• Step 2: Phone rings at the called party
• Step 3: Caller waits for the response
• Step 4: Called party picks up the phone
• Step 5: Conversation begins between them
• Step 6: After the conversation, both disconnect the call
Algorithm: Example

Problem: To add two numbers.

• Step1: Start.
• Step2: Take the two numbers.
• Step3: Add the two numbers.
• Step4: Print the result.
• Step5: Stop.
Program to add two numbers
#include <stdio.h>
int main() {
int number1, number2, sum;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
// calculate the sum
sum = number1 + number2;
printf("%d + %d = %d", number1, number2, sum);
return 0;
}
POLL
Q. Algorithm is defined as “ the ________set of steps, which provide a
chain of action for solving a _______”.
a)temporary, instruction
b)actual, issue
c)instruction, problem
d)finite, problem
We will discuss:

 What is Flow Chart?

 Types of Programming Methodologies

 Top Down Approach

 Problems of Algorithms and Flow Chart


Flow Chart
• The first design of flowchart was designed by John Von
Neumann in 1945.

• Flowchart uses different symbols to design a solution to a


problem. It is another commonly used programming tool.

• By looking at a Flowchart one can understand the


sequence of operations performed in a system.
Advantages of Flow Chart
• Flowchart is an excellent way of communicating the logic
of a program.

• Easy and efficient to analyze problem using flowchart.

• During program development cycle, the flowchart plays


the role of a blueprint, which makes program
development process easier.
Contd..
• After successful development of a program, it needs
continuous timely maintenance during the course of its
operation.

• The flowchart makes program or system maintenance


easier.

• It is easy to convert the flowchart into any programming


language code.
POLL
Q. _________converts the programs written in
assembly language into machine instructions .

a) Compiler
b) Interpreter
c) Assembler
d) Converter
POLL
Q. Which of the following is called low level languages?

a)Machine language

b)Assembly language

c)Both a and b

d)None of above
Flow Chart Symbols
Example: Addition of 2 numbers
START

TAKE TWO
NUMBERS A and B

FIND SUM=A+B

PRINT SUM

STOP
Programming Methodologies
The approach to analyzing complex problems, planning for
software development and controlling the development
process is called programming methodology.

For example:
When programs are developed to solve real-life problems
like inventory management, payroll processing, student
admissions, examination result processing etc. They all
tend to be complex.
Types of Programming
Methodologies
 Procedural Programming

 Functional Programming

Object Oriented Programming


Procedural Programming
• Problem is broken down into procedures, or blocks of
code that perform one task each.
• All procedures taken together form the whole program.
• It is suitable only for small programs that have low level of
complexity.

For Example: C, FORTRAN, PASCAL are comes under


procedure oriented programming languages.
Functional Programming
• Functional programming languages are specially
designed to handle symbolic computation and list
processing applications.

• Functional programming is based on mathematical


functions.

• Some of the popular functional programming languages


include: Lisp, Python etc.
Object Oriented Programming

• Object Oriented programming (OOP) is a programming


that relies on the concept of classes and objects.

• Because OOP is a programming, there are many object-


oriented programming languages including: C++, Java, and
Python.
POLL
Q. Which of the following might be used to convert high level language
instructions into machine language code is

a)Assembler
b)System software
c)Compiler
d)Translator
POLL
Q. What is true about machine language

a)It is understood by the computer


b)It may always be represented by binary numbers
c)Both a and b
d)None of the above
Example: Programming
Methodologies
Top Down Approach
• The basic idea in top-down approach is to break a
complex algorithm or a problem into smaller segments
called modules, this process is also called
as modularization.

• The C- programming language uses the top-down


approach of solving a problem in which the flow of
control is in the downward direction.
Top-Down Approach
In this approach, the problem is broken down into smaller parts.
It is generally used by structured programming languages such as C,
COBOL, FORTRAN, etc.
It is generally used with documentation of module and debugging
code.
Contd…
 It does not require communication between modules.
 It contains redundant information.
 Decomposition approach is used here.
 The implementation depends on the programming language and
platform.
PRACTICE QUESTIONS
Q1. Write an algorithm & flowchart to find the sum of two
numbers. Sum=(a+b);
Q2. Write an algorithm & flowchart to find the area of
rectangle. Rect=(l*b);
Q3. Write an algorithm & flowchart to find the area of a
circle. Area=(3.14*r*r);
Q4. Write an algorithm & flowchart to find the simple
interest. SI=(p*n*r)/100;

You might also like