SlideShare a Scribd company logo
SUBJECT:PROGRAMMING IN C (CS-205)
DIPLOMA(1ST YEAR ECE)
YEAR-SEM-I-II
B.DINESH
ASSISTANT PROFESSOR
CSE(AI&ML)DEPT
UNIT-I
PROGRAMMING METHODOLOGY AND
INTROUCTION TO C LANGUAGE
1.STEPS INVOLVE IN PROBLEM
SOLVING:
Problem-solving is a sequential process of analyzing
information related to a given situation and generating
appropriate response options.
In order to solve a problem with the computer, one
has to pass through certain stages or steps. They are as
follows:
Steps to Solve a Problem With the
Computer :
Step 1: Understanding the Problem:
Here we try to understand the problem to be solved in
totally. We should be absolutely sure about the
objectives of the given problem.
Step 2: Analyzing the Problem:
• After understanding thoroughly, the problem to be
solved, we look at different ways of solving the problem
and evaluate each of these methods.
Step 3: Developing the solution:
• Here, the overview of the sequence of operations that
was the result of the analysis stage is expanded to form
a detailed step by step solution to the problem under
consideration.
Step 4: Coding and Implementation:
• The last stage of problem-solving is the conversion of the
detailed sequence of operations into a language that the
computer can understand.
• Here, each step is converted to its equivalent instruction or
instructions in the computer language that has been chosen
for the implantation.
This set of instruction is called a program with problem
solving through programming in C.
Let us look into the steps one by
one:
1. Problem Definition Phase:
2. Getting Started on a Problem:
3. Use of Specific Examples:
4. Similarities Among Problems:
5. Working Backwards from the Solution:
2.Define algorithm and know its
characteristics
•An algorithm is a step-by-step procedure or a set
of well-defined instructions designed to perform
a specific task or solve a problem. It is a logical
and systematic approach that ensures a desired
outcome when executed correctly.
Qualities of Good Algorithms
• Input and output should be defined precisely.
• Each step in the algorithm should be clear and unambiguous.
• Algorithms should be most effective among many different ways to
solve a problem.
• An algorithm shouldn't include computer code. Instead, the algorithm
should be written in such a way that it can be used in different
programming languages.
Characteristics of an Algorithm:
1. Finiteness:
o The algorithm must terminate after a finite number of steps. It cannot go on indefinitely.
2. Definiteness:
o Each step of the algorithm must be precisely defined and unambiguous. There should be no room
for confusion.
3. Input:
o An algorithm may have zero or more inputs provided externally to act upon.
4. Output:
o It must produce at least one output, which is the solution or result of the problem.
5.Effectiveness:
o Every step of the algorithm should be basic enough to be performed manually or by a
computing machine within a reasonable amount of time.
6.Generality:
o The algorithm should solve all problems of a particular type, not just one specific instance.
7.Language Independence:
o An algorithm can be expressed in any language (natural or programming) without affecting its
functionality.
8.Order of Execution:
o The steps must be executed in a specific order, ensuring a logical flow to achieve the desired
output.
Example of an Algorithm (Basic Example:
Find the Sum of Two Numbers):
• Step 1: Start
Step 2: Take two inputs, A and B.
Step 3: Add the two numbers: Sum = A + B.
Step 4: Display the result, Sum.
Step 5: Stop
• This illustrates the basic principles of an algorithm: clear inputs, step-by-step instructions, and a
defined output.
3.STEPS INVOLVED IN ALGORITHM
DEVELOPMENT:
• 1. Problem definition
2. Development of a model
3. Specification of Algorithm
4. Designing an Algorithm
5. Checking the correctness of Algorithm
6. Analysis of Algorithm
7. Implementation of Algorithm
8. Program testing
9. Documentation Preparation.
• 1. Problem Definition
• Understand the problem in detail.
• Clearly define the inputs, outputs, and any constraints.
• Set clear objectives for solving the problem.
• 2. Development of a Model
• Create a model (mathematical, graphical, or logical) to represent the
problem.
• This model acts as a blueprint to design the algorithm.
• Identify relationships between input data and expected results.
• 3. Specification of Algorithm
• Define the high-level operations and steps required to solve the
problem.
• Specify how the algorithm should function, including its constraints
and assumptions.
• Ensure the specification is precise and unambiguous.
• 4. Designing an Algorithm
• Develop a step-by-step procedure or pseudocode to solve the
problem.
• Consider different algorithmic approaches (e.g., divide and conquer,
greedy, dynamic programming).
• Focus on clarity, efficiency, and simplicity during the design phase.
• 5. Checking the Correctness of Algorithm
• Validate that the algorithm produces correct results for all possible
inputs.
• Use test cases, proofs, or logical reasoning to verify its correctness.
• Consider edge cases and unexpected inputs.
• 6. Analysis of Algorithm
• Analyze the algorithm for:
• Time Complexity: How fast the algorithm performs as input size grows.
• Space Complexity: The amount of memory required during execution.
• Optimize the algorithm to improve performance, if necessary.
• 7. Implementation of Algorithm
• Translate the designed algorithm into a programming language.
• Use best coding practices for readability, maintainability, and efficiency.
• Modularize the code for easier debugging and future modifications.
• 8. Program Testing
• Test the implemented algorithm with various test cases, including:
• Normal inputs
• Edge cases
• Stress tests (large datasets)
• Debug and refine the code as needed.
• 9. Documentation Preparation
• Prepare comprehensive documentation that includes:
• Problem description
• Algorithm steps or pseudocode
• Input/output specifications
• Performance analysis (time and space complexity)
• Instructions for usage and examples
4.ALGORITHM:
• 1.write an algorithm to find the sum of two numbers:
1.Start
2.Input two numbers, num1 and num2.
3.Calculate the sum: sum = num1 + num2.
4.Output the result, sum.
• Stop
Algorithm to Convert Temperature from Celsius
to Fahrenheit
1. Start
2. Input the temperature in Celsius, Celsius.
3. Convert it to Fahrenheit using the formula:
Fahrenheit=(celsius×9/5)+32fahrenheit = (Celsius times 9/5) +
32fahrenheit=(celsius×9/5)+32
• Output the temperature in Fahrenheit
• stop
Algorithm to Find Area and Perimeter of a
Rectangle
• Algorithm to Find Area and Perimeter of a Rectangle
1. Start
2. Input the length length and width width of the rectangle.
3. Calculate the area using the formula: area=length×widtharea = length times
widtharea=length×width
4. Calculate the perimeter using the formula: perimeter=2×(length+width)perimeter = 2
times (length + width)perimeter=2×(length+width)
5. Output the area and perimeter.
6. Stop
5. Define flowchart and know symbols used
in drawing flowchart
• What is a Flowchart?
A flowchart is a graphical representations of steps. It was originated
from computer science as a tool for representing algorithms and
programming logic but had extended to use in all other kinds of
processes.
hey help us visualize complex processes, or make explicit the
structure of problems and tasks. A flowchart can also be used to define
a process or project to be implemented.
Flowchart Symbols:
1. Terminal
• The terminator symbol represents the starting or ending point of the
system.
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
2. Data:
• This is a parallelogram-shaped box
inside which the inputs or outputs are
written.
3. Process:
•This is a rectangular box inside
which a programmer writes the
main course of action of the
algorithm or the main logic of the
program.
4. Decision:
• This is a rhombus-shaped box, control
statements like if, condition like
• a > 0, are written inside this box.
5. Flow:
• This arrow line represents the flow of the algorithm or process. It
represents the direction of the process flow.
6.Flowchart Example
• A flowchart can also be
used in visualizing
algorithms, regardless of
its complexity. Here is
an example that shows
how flowchart can be
used in showing a
simple summation
process.
6.Draw flowchart for simple problems: flowchart to calculate the average of
two numbers:
7.Differentiate algorithm and flowchart:
S. No Algorithm Flowchart
1.
An algorithm is a step-by-step procedure to solve a
problem.
A flowchart is a diagram created with different shapes
to show the flow of data.
2. The algorithm is complex to understand. A flowchart is easy to understand.
3. In the algorithm, plain text is used. In the flowchart, symbols/shapes are used.
4. The algorithm is easy to debug. A flowchart is hard to debug.
5. The algorithm is difficult to construct. A flowchart is simple to construct.
6. The algorithm does not follow any rules. The flowchart follows rules to be constructed.
7. The algorithm is the pseudo-code for the program.
A flowchart is just a graphical representation of that
logic.
8. Definition of a Program:
• A program is a set of instructions written in a programming
language that tells a computer what tasks to perform and how to
perform them. Programs are designed to solve specific problems,
automate tasks, or process data.
Differentiate between program and algorithm:
Aspect Algorithm Program
Definitio
n
A step-by-step procedure to solve a problem or perform a
task.
A set of instructions written in a programming language for execution by a
computer.
Nature Abstract and conceptual. Concrete and implemented in code.
Languag
e
It is written using plain English language and can be
understood by those from a non-programming background.
It could be written in any programming language, such as Python, Java, C++,
JavaScript, or any other language, depending on the task the program is
designed for.
Executio
n
A person can execute an algorithm. A program is always executed by a computer.
Purpose Describes the logic to solve a problem. Implements the logic to perform tasks.
Flexibilit
y
Independent of any programming language or platform. Depends on the programming language and the target platform.
Level of
Detail
High-level and focuses on logic and strategy. Detailed and includes specific instructions for the computer.
Output A plan or strategy for solving a problem. A functional application or system.
9.Define High Level And Low Level Language:
• High-Level Language:
• High-level languages are easier for humans to understand and write, while low-level
languages are closer to machine code and hardware.
• High-level languages
 Ease of use: High-level languages are easier to learn, read, and debug.
 Portability: High-level languages are portable and don't depend on machines.
 Abstraction: High-level languages use abstraction, or information hiding, to eliminate
unnecessary details.
 Examples: Examples include Python, C++, C, C#, Visual Basic, and JavaScript.
Low-Level Language:
• A low-level language is a programming language that is similar to machine code and
hardware. It gives programmers direct control over a computer's hardware and
resources.
 Ease of use: Low-level languages are considered difficult to use because of the many
technical details to remember.
 Portability: Low-level languages are machine-dependent and not portable.
 Abstraction: Low-level languages provide little or no abstraction from a computer's
instruction set architecture.
 Examples: Examples include machine language and assembly language.
Feature High-Level Language Low-Level Language
Abstraction High (abstracts hardware details) Low (close to hardware)
Ease of Use Easy to learn and use Harder to learn and use
Portability Portable (platform-independent) Not portable (platform-specific)
Execution Speed Slower (requires translation) Faster (direct hardware access)
Examples Python, Java, C++ Assembly, Machine Code
Comparison:
10.Define Compiler,Assembler,Linker And
Loader
• 1.COMPILER:
• A compiler is a software tool that translates a program written in a
high-level language (like C++, Java, or Python) into a low-level
language (like machine code or assembly language) that the computer
can understand.
• Functions:
• Converts source code into an intermediate or machine-level
representation.
• Detects and reports syntax and semantic errors in the source code.
• Optimizes the code for better performance.
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
• 2. Assembler:
• An assembler is a program that translates assembly language
(low-level language) into machine language (binary code).
• Functions:
 Converts assembly instructions (e.g., MOV, ADD) into binary
instructions.
 Generates an object file for further processing.
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
• 3. Linker:
• A linker is a program that combines one or more object files generated
by the compiler or assembler into a single executable file.
• Functions:
 Resolves references between different modules or object files (e.g.,
connecting function calls in one file to definitions in another).
 Links necessary libraries or system resources with the program.
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
• 4. Loader:
• A loader is a part of the operating system responsible for loading the executable
file into the computer's memory and preparing it for execution.
• Functions:
 Loads the executable into RAM.
 Allocates necessary memory space for the program.
 Links dynamic libraries during runtime (if required).
 Starts the execution of the program by transferring control to its entry point.
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
Define Source Code Assembly Code Object
Code, Machine Code
• 1. Source Code
• Definition: Source code refers to the human-readable instructions written by a programmer
in a high-level programming language (e.g., Python, Java, C++).
• Key Features:
• Written using syntax that is easy for humans to understand.
• Requires translation (compilation or interpretation) into machine-readable form.
• print("Hello, world!")
• 2. Assembly Code:
• Definition: Assembly code (or assembly language) is a low-level programming language
that uses symbolic instructions to represent machine code.
• Key Features:
 Closer to hardware than source code but still somewhat human-readable.
 Uses (e.g., MOV, ADD, SUB) to represent machine instructions.
 Needs to be translated into machine code using an assembler.
 EX: MOV AX, 5
• ADD AX, 3(After running these two instructions: AX = 8)
• 3. Object Code
 Definition: Object code is the intermediate, machine-readable output generated by a
compiler or assembler from source code or assembly code.
 Key Features:
o Typically not directly executable.
o May include unresolved references (e.g., to functions or libraries).
o Used in the linking phase to create executable code.
o Example: Binary code in .obj or .o files.
• 4. Machine Code
 Machine code is the final, low-level code that consists of binary instructions (0s and 1s) directly understood and executed by a computer's
CPU.
 Key Features:
o Not human-readable.
o Directly runs on hardware without further translation.
o Example:
• 10111000 00000101
• 00000111 00000011
• Relationship Between Them
 Source Code → Compiled/Assembled → Assembly Code → Assembled → Object Code → Linked →
Machine Code.
•
12.importance of C language
• C programming is a general-purpose, procedural, imperative
computer programming language.
• It was named ‘C’ because it is an of BCPL (Basic Combined
Programming Language) which was popularly called ‘B’ language.
• C is called as a robust language(Strong lang), which has so many built-in
functions and operations, which can be used to write any complex program.
• Generally, we use to call C as a middle level language. Because, the ‘C’
compiler combines the capabilities of an assembly language with the features
of a high-level language.
• Therefore, it is best for writing both system software and business packages.
C programming language is a machine-independent programming
language mainly used to create many applications and operating systems, such as
Windows, and other complicated programs, such as the Oracle database,
Git, Python interpreter, and games.
It is considered a programming foundation in learning any other programming
language. Such applications include operating systems and diverse software for
computer
structure of C program
• 1. Documentation Section (Optional)
 Purpose: Add comments to describe the program, including its purpose, author, creation
date, etc.
 Syntax: Comments can be single-line (//) or multi-line (/* ... */).
• Program: Example Program
• Author: Your Name
• Date: DD-MM-YYYY
• Description: This program demonstrates the basic structure of a C program.
• 2. Preprocessor Directives:
 Purpose: Include necessary header files and macros before compilation.
 Syntax: #include is used to include libraries, and #define is used to define
constants.
• #include <stdio.h> // Standard Input/Output header
• #include <stdlib.h> // Standard Library
•3. Global Declarations (Optional)
 Purpose: Declare global variables, constants, and function prototypes that
can be used throughout the program.
 Syntax:
• int globalVariable = 10; // Global variable declaration
• void displayMessage(); // Function prototype
• 4. The main () Function:
 Purpose: The entry point of the program where execution begins.
 Structure:
• int main ()
• {
• // Variable declarations
• // Program logic
• return 0; // Indicates successful program termination
• }
• The main () function is mandatory in every C program
• 5. Global Declarations:
 The global declaration section contains global variables, function declaration, and static
variables. Variables and functions which are declared in this scope can be used
anywhere in the program.
• Example:
• int num = 18;
• 6. Statements/Instructions
 Purpose: The core logic of the program, such as input/output, loops,
conditions, and function calls.
 Example:
• printf("Hello, World!n");{ n: Purpose: Inserts a newline in the
output.}
•
• 7. User-Defined Functions (Optional)
 Purpose: Define reusable blocks of code to improve modularity and
readability.
 Syntax:
• void display Message()
• {
• printf("This is a user-defined function.n");
• }
• 8. Return Statement
 Purpose: End the main() function and optionally return a value to
the operating system.
 Syntax:
• return 0; // Typically used to indicate successful execution
•Example of a Simple C Program
• #include <stdio.h> // Preprocessor directive
• int main()
• {
• printf("Hello, Worldn");
• }
• Output
• Hello world
•
Different stages in converting the c
program source code into an
executable code
•The process of converting C program source
code into executable code involves several
stages. Here's a breakdown of these stages:
Compilation process in c
• What is a compilation?
• The compilation is a process of converting the source code into
object code. It is done with the help of the compiler. The
compiler checks the source code for the syntactical or structural
errors, and if the source code is error-free, then it generates the
object code.
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
• The c compilation process converts the source code taken as input into the
object code or machine code. The compilation process can be divided into
four steps, i.e., Pre-processing, Compiling, Assembling, and Linking.
• The preprocessor takes the source code as an input, and it removes all the
comments from the source code. The preprocessor takes the preprocessor
directive and interprets it. For example, if <stdio.h>, the directive is available
in the program, then the preprocessor interprets the directive and replace this
directive with the content of the 'stdio.h' file.
• The following are the phases through which program passes before being
transformed into an executable form:
 Preprocessor
 Compiler
 Assembler
 Linker
• 1.Preprocessor
• The source code is the code which is written in a text editor and the source
code file is given an extension ".c". This source code is first passed to the
preprocessor, and then the preprocessor expands this code. After expanding
the code, the expanded code is passed to the compiler.
• 2.Compiler
• The code which is expanded by the preprocessor is passed to the compiler.
The compiler converts this code into assembly code. Or we can say that the
C compiler converts the pre-processed code into assembly code.
• 3.Assembler
• The assembly code is converted into object code by using an assembler. The name
of the object file generated by the assembler is the same as the source file. The
extension of the object file in DOS is '.obj,' and in UNIX, the extension is 'o'. If the
name of the source file is 'hello.c', then the name of the object file would be
'hello.obj’.
• 4.Linker
• Mainly, all the programs written in C use library functions. These library functions
are pre-compiled, and the object code of these library files is stored with '.lib' (or
'.a') extension. The main working of the linker is to combine the object code of
library files with the object code of our program.
1.#include <stdio.h>
2.int main()
3.{
4. printf("Hello javaTpoint");
5. return 0;
6.}
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
Executing a program written in C-Language involves
a series of steps. These are :
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd

More Related Content

Similar to PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd (20)

PPTX
UNIT-1.pptx python for engineering first year students
SabarigiriVason
 
PPSX
Algorithm and flowchart
Sachin Goyani
 
PPTX
Algorithm and flowchart
Elizabeth de Leon Aler
 
PPTX
Algorithm and flowchart.pptx
MaheShiva
 
PDF
Unit 1-problem solving with algorithm
rajkumar1631010038
 
PPT
Algo.ppt
AyeshaAshiq7
 
PDF
Problem solving methodology
Prof. Dr. K. Adisesha
 
PPTX
Chp-1 DAA (2).pptx design analysis and algoritham presentation
vaishnavbhavna17
 
PPT
Unit 1 python (2021 r)
praveena p
 
PDF
Study Material for Problem Solving Techniques
Bobby Murugesan
 
PPTX
PCCF UNIT - 1 - M.Sudharsan.pptx
sudharsanm56
 
PPT
3 algorithm-and-flowchart
Rohit Shrivastava
 
PPTX
Algorithm,Pseudocode,Flowchart.pptx
DrThenmozhiKarunanit
 
PPTX
Introduction to problem solving Techniques
merlinjohnsy
 
PPTX
Flowchart and algorithm
DHANIK VIKRANT
 
PPTX
Module 1 python.pptx
AnuragJoshi813963
 
PPTX
flowchart & algorithms
Student
 
PPT
Chap6
artipradhan
 
PPT
Unit 1 psp
Karthi Vel
 
PPTX
Chapter #1 (Introduction To Algorithms).pptx
hekmatyarzahir44
 
UNIT-1.pptx python for engineering first year students
SabarigiriVason
 
Algorithm and flowchart
Sachin Goyani
 
Algorithm and flowchart
Elizabeth de Leon Aler
 
Algorithm and flowchart.pptx
MaheShiva
 
Unit 1-problem solving with algorithm
rajkumar1631010038
 
Algo.ppt
AyeshaAshiq7
 
Problem solving methodology
Prof. Dr. K. Adisesha
 
Chp-1 DAA (2).pptx design analysis and algoritham presentation
vaishnavbhavna17
 
Unit 1 python (2021 r)
praveena p
 
Study Material for Problem Solving Techniques
Bobby Murugesan
 
PCCF UNIT - 1 - M.Sudharsan.pptx
sudharsanm56
 
3 algorithm-and-flowchart
Rohit Shrivastava
 
Algorithm,Pseudocode,Flowchart.pptx
DrThenmozhiKarunanit
 
Introduction to problem solving Techniques
merlinjohnsy
 
Flowchart and algorithm
DHANIK VIKRANT
 
Module 1 python.pptx
AnuragJoshi813963
 
flowchart & algorithms
Student
 
Unit 1 psp
Karthi Vel
 
Chapter #1 (Introduction To Algorithms).pptx
hekmatyarzahir44
 

Recently uploaded (20)

PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Ad

PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd

  • 1. SUBJECT:PROGRAMMING IN C (CS-205) DIPLOMA(1ST YEAR ECE) YEAR-SEM-I-II B.DINESH ASSISTANT PROFESSOR CSE(AI&ML)DEPT
  • 3. 1.STEPS INVOLVE IN PROBLEM SOLVING: Problem-solving is a sequential process of analyzing information related to a given situation and generating appropriate response options. In order to solve a problem with the computer, one has to pass through certain stages or steps. They are as follows:
  • 4. Steps to Solve a Problem With the Computer : Step 1: Understanding the Problem: Here we try to understand the problem to be solved in totally. We should be absolutely sure about the objectives of the given problem.
  • 5. Step 2: Analyzing the Problem: • After understanding thoroughly, the problem to be solved, we look at different ways of solving the problem and evaluate each of these methods. Step 3: Developing the solution: • Here, the overview of the sequence of operations that was the result of the analysis stage is expanded to form a detailed step by step solution to the problem under consideration.
  • 6. Step 4: Coding and Implementation: • The last stage of problem-solving is the conversion of the detailed sequence of operations into a language that the computer can understand. • Here, each step is converted to its equivalent instruction or instructions in the computer language that has been chosen for the implantation. This set of instruction is called a program with problem solving through programming in C.
  • 7. Let us look into the steps one by one: 1. Problem Definition Phase: 2. Getting Started on a Problem: 3. Use of Specific Examples: 4. Similarities Among Problems: 5. Working Backwards from the Solution:
  • 8. 2.Define algorithm and know its characteristics •An algorithm is a step-by-step procedure or a set of well-defined instructions designed to perform a specific task or solve a problem. It is a logical and systematic approach that ensures a desired outcome when executed correctly.
  • 9. Qualities of Good Algorithms • Input and output should be defined precisely. • Each step in the algorithm should be clear and unambiguous. • Algorithms should be most effective among many different ways to solve a problem. • An algorithm shouldn't include computer code. Instead, the algorithm should be written in such a way that it can be used in different programming languages.
  • 10. Characteristics of an Algorithm: 1. Finiteness: o The algorithm must terminate after a finite number of steps. It cannot go on indefinitely. 2. Definiteness: o Each step of the algorithm must be precisely defined and unambiguous. There should be no room for confusion. 3. Input: o An algorithm may have zero or more inputs provided externally to act upon. 4. Output: o It must produce at least one output, which is the solution or result of the problem.
  • 11. 5.Effectiveness: o Every step of the algorithm should be basic enough to be performed manually or by a computing machine within a reasonable amount of time. 6.Generality: o The algorithm should solve all problems of a particular type, not just one specific instance. 7.Language Independence: o An algorithm can be expressed in any language (natural or programming) without affecting its functionality. 8.Order of Execution: o The steps must be executed in a specific order, ensuring a logical flow to achieve the desired output.
  • 12. Example of an Algorithm (Basic Example: Find the Sum of Two Numbers): • Step 1: Start Step 2: Take two inputs, A and B. Step 3: Add the two numbers: Sum = A + B. Step 4: Display the result, Sum. Step 5: Stop • This illustrates the basic principles of an algorithm: clear inputs, step-by-step instructions, and a defined output.
  • 13. 3.STEPS INVOLVED IN ALGORITHM DEVELOPMENT: • 1. Problem definition 2. Development of a model 3. Specification of Algorithm 4. Designing an Algorithm 5. Checking the correctness of Algorithm 6. Analysis of Algorithm 7. Implementation of Algorithm 8. Program testing 9. Documentation Preparation.
  • 14. • 1. Problem Definition • Understand the problem in detail. • Clearly define the inputs, outputs, and any constraints. • Set clear objectives for solving the problem. • 2. Development of a Model • Create a model (mathematical, graphical, or logical) to represent the problem. • This model acts as a blueprint to design the algorithm. • Identify relationships between input data and expected results.
  • 15. • 3. Specification of Algorithm • Define the high-level operations and steps required to solve the problem. • Specify how the algorithm should function, including its constraints and assumptions. • Ensure the specification is precise and unambiguous. • 4. Designing an Algorithm • Develop a step-by-step procedure or pseudocode to solve the problem. • Consider different algorithmic approaches (e.g., divide and conquer, greedy, dynamic programming). • Focus on clarity, efficiency, and simplicity during the design phase.
  • 16. • 5. Checking the Correctness of Algorithm • Validate that the algorithm produces correct results for all possible inputs. • Use test cases, proofs, or logical reasoning to verify its correctness. • Consider edge cases and unexpected inputs. • 6. Analysis of Algorithm • Analyze the algorithm for: • Time Complexity: How fast the algorithm performs as input size grows. • Space Complexity: The amount of memory required during execution. • Optimize the algorithm to improve performance, if necessary.
  • 17. • 7. Implementation of Algorithm • Translate the designed algorithm into a programming language. • Use best coding practices for readability, maintainability, and efficiency. • Modularize the code for easier debugging and future modifications. • 8. Program Testing • Test the implemented algorithm with various test cases, including: • Normal inputs • Edge cases • Stress tests (large datasets) • Debug and refine the code as needed.
  • 18. • 9. Documentation Preparation • Prepare comprehensive documentation that includes: • Problem description • Algorithm steps or pseudocode • Input/output specifications • Performance analysis (time and space complexity) • Instructions for usage and examples
  • 19. 4.ALGORITHM: • 1.write an algorithm to find the sum of two numbers: 1.Start 2.Input two numbers, num1 and num2. 3.Calculate the sum: sum = num1 + num2. 4.Output the result, sum. • Stop
  • 20. Algorithm to Convert Temperature from Celsius to Fahrenheit 1. Start 2. Input the temperature in Celsius, Celsius. 3. Convert it to Fahrenheit using the formula: Fahrenheit=(celsius×9/5)+32fahrenheit = (Celsius times 9/5) + 32fahrenheit=(celsius×9/5)+32 • Output the temperature in Fahrenheit • stop
  • 21. Algorithm to Find Area and Perimeter of a Rectangle • Algorithm to Find Area and Perimeter of a Rectangle 1. Start 2. Input the length length and width width of the rectangle. 3. Calculate the area using the formula: area=length×widtharea = length times widtharea=length×width 4. Calculate the perimeter using the formula: perimeter=2×(length+width)perimeter = 2 times (length + width)perimeter=2×(length+width) 5. Output the area and perimeter. 6. Stop
  • 22. 5. Define flowchart and know symbols used in drawing flowchart • What is a Flowchart? A flowchart is a graphical representations of steps. It was originated from computer science as a tool for representing algorithms and programming logic but had extended to use in all other kinds of processes. hey help us visualize complex processes, or make explicit the structure of problems and tasks. A flowchart can also be used to define a process or project to be implemented.
  • 23. Flowchart Symbols: 1. Terminal • The terminator symbol represents the starting or ending point of the system.
  • 25. 2. Data: • This is a parallelogram-shaped box inside which the inputs or outputs are written.
  • 26. 3. Process: •This is a rectangular box inside which a programmer writes the main course of action of the algorithm or the main logic of the program.
  • 27. 4. Decision: • This is a rhombus-shaped box, control statements like if, condition like • a > 0, are written inside this box.
  • 28. 5. Flow: • This arrow line represents the flow of the algorithm or process. It represents the direction of the process flow.
  • 29. 6.Flowchart Example • A flowchart can also be used in visualizing algorithms, regardless of its complexity. Here is an example that shows how flowchart can be used in showing a simple summation process.
  • 30. 6.Draw flowchart for simple problems: flowchart to calculate the average of two numbers:
  • 31. 7.Differentiate algorithm and flowchart: S. No Algorithm Flowchart 1. An algorithm is a step-by-step procedure to solve a problem. A flowchart is a diagram created with different shapes to show the flow of data. 2. The algorithm is complex to understand. A flowchart is easy to understand. 3. In the algorithm, plain text is used. In the flowchart, symbols/shapes are used. 4. The algorithm is easy to debug. A flowchart is hard to debug. 5. The algorithm is difficult to construct. A flowchart is simple to construct. 6. The algorithm does not follow any rules. The flowchart follows rules to be constructed. 7. The algorithm is the pseudo-code for the program. A flowchart is just a graphical representation of that logic.
  • 32. 8. Definition of a Program: • A program is a set of instructions written in a programming language that tells a computer what tasks to perform and how to perform them. Programs are designed to solve specific problems, automate tasks, or process data.
  • 33. Differentiate between program and algorithm: Aspect Algorithm Program Definitio n A step-by-step procedure to solve a problem or perform a task. A set of instructions written in a programming language for execution by a computer. Nature Abstract and conceptual. Concrete and implemented in code. Languag e It is written using plain English language and can be understood by those from a non-programming background. It could be written in any programming language, such as Python, Java, C++, JavaScript, or any other language, depending on the task the program is designed for. Executio n A person can execute an algorithm. A program is always executed by a computer. Purpose Describes the logic to solve a problem. Implements the logic to perform tasks. Flexibilit y Independent of any programming language or platform. Depends on the programming language and the target platform. Level of Detail High-level and focuses on logic and strategy. Detailed and includes specific instructions for the computer. Output A plan or strategy for solving a problem. A functional application or system.
  • 34. 9.Define High Level And Low Level Language: • High-Level Language: • High-level languages are easier for humans to understand and write, while low-level languages are closer to machine code and hardware. • High-level languages  Ease of use: High-level languages are easier to learn, read, and debug.  Portability: High-level languages are portable and don't depend on machines.  Abstraction: High-level languages use abstraction, or information hiding, to eliminate unnecessary details.  Examples: Examples include Python, C++, C, C#, Visual Basic, and JavaScript.
  • 35. Low-Level Language: • A low-level language is a programming language that is similar to machine code and hardware. It gives programmers direct control over a computer's hardware and resources.  Ease of use: Low-level languages are considered difficult to use because of the many technical details to remember.  Portability: Low-level languages are machine-dependent and not portable.  Abstraction: Low-level languages provide little or no abstraction from a computer's instruction set architecture.  Examples: Examples include machine language and assembly language.
  • 36. Feature High-Level Language Low-Level Language Abstraction High (abstracts hardware details) Low (close to hardware) Ease of Use Easy to learn and use Harder to learn and use Portability Portable (platform-independent) Not portable (platform-specific) Execution Speed Slower (requires translation) Faster (direct hardware access) Examples Python, Java, C++ Assembly, Machine Code Comparison:
  • 37. 10.Define Compiler,Assembler,Linker And Loader • 1.COMPILER: • A compiler is a software tool that translates a program written in a high-level language (like C++, Java, or Python) into a low-level language (like machine code or assembly language) that the computer can understand. • Functions: • Converts source code into an intermediate or machine-level representation. • Detects and reports syntax and semantic errors in the source code. • Optimizes the code for better performance.
  • 39. • 2. Assembler: • An assembler is a program that translates assembly language (low-level language) into machine language (binary code). • Functions:  Converts assembly instructions (e.g., MOV, ADD) into binary instructions.  Generates an object file for further processing.
  • 41. • 3. Linker: • A linker is a program that combines one or more object files generated by the compiler or assembler into a single executable file. • Functions:  Resolves references between different modules or object files (e.g., connecting function calls in one file to definitions in another).  Links necessary libraries or system resources with the program.
  • 43. • 4. Loader: • A loader is a part of the operating system responsible for loading the executable file into the computer's memory and preparing it for execution. • Functions:  Loads the executable into RAM.  Allocates necessary memory space for the program.  Links dynamic libraries during runtime (if required).  Starts the execution of the program by transferring control to its entry point.
  • 46. Define Source Code Assembly Code Object Code, Machine Code • 1. Source Code • Definition: Source code refers to the human-readable instructions written by a programmer in a high-level programming language (e.g., Python, Java, C++). • Key Features: • Written using syntax that is easy for humans to understand. • Requires translation (compilation or interpretation) into machine-readable form. • print("Hello, world!")
  • 47. • 2. Assembly Code: • Definition: Assembly code (or assembly language) is a low-level programming language that uses symbolic instructions to represent machine code. • Key Features:  Closer to hardware than source code but still somewhat human-readable.  Uses (e.g., MOV, ADD, SUB) to represent machine instructions.  Needs to be translated into machine code using an assembler.  EX: MOV AX, 5 • ADD AX, 3(After running these two instructions: AX = 8)
  • 48. • 3. Object Code  Definition: Object code is the intermediate, machine-readable output generated by a compiler or assembler from source code or assembly code.  Key Features: o Typically not directly executable. o May include unresolved references (e.g., to functions or libraries). o Used in the linking phase to create executable code. o Example: Binary code in .obj or .o files.
  • 49. • 4. Machine Code  Machine code is the final, low-level code that consists of binary instructions (0s and 1s) directly understood and executed by a computer's CPU.  Key Features: o Not human-readable. o Directly runs on hardware without further translation. o Example: • 10111000 00000101 • 00000111 00000011 • Relationship Between Them  Source Code → Compiled/Assembled → Assembly Code → Assembled → Object Code → Linked → Machine Code. •
  • 50. 12.importance of C language • C programming is a general-purpose, procedural, imperative computer programming language. • It was named ‘C’ because it is an of BCPL (Basic Combined Programming Language) which was popularly called ‘B’ language.
  • 51. • C is called as a robust language(Strong lang), which has so many built-in functions and operations, which can be used to write any complex program. • Generally, we use to call C as a middle level language. Because, the ‘C’ compiler combines the capabilities of an assembly language with the features of a high-level language. • Therefore, it is best for writing both system software and business packages.
  • 52. C programming language is a machine-independent programming language mainly used to create many applications and operating systems, such as Windows, and other complicated programs, such as the Oracle database, Git, Python interpreter, and games. It is considered a programming foundation in learning any other programming language. Such applications include operating systems and diverse software for computer
  • 53. structure of C program
  • 54. • 1. Documentation Section (Optional)  Purpose: Add comments to describe the program, including its purpose, author, creation date, etc.  Syntax: Comments can be single-line (//) or multi-line (/* ... */). • Program: Example Program • Author: Your Name • Date: DD-MM-YYYY • Description: This program demonstrates the basic structure of a C program.
  • 55. • 2. Preprocessor Directives:  Purpose: Include necessary header files and macros before compilation.  Syntax: #include is used to include libraries, and #define is used to define constants. • #include <stdio.h> // Standard Input/Output header • #include <stdlib.h> // Standard Library
  • 56. •3. Global Declarations (Optional)  Purpose: Declare global variables, constants, and function prototypes that can be used throughout the program.  Syntax: • int globalVariable = 10; // Global variable declaration • void displayMessage(); // Function prototype
  • 57. • 4. The main () Function:  Purpose: The entry point of the program where execution begins.  Structure: • int main () • { • // Variable declarations • // Program logic • return 0; // Indicates successful program termination • } • The main () function is mandatory in every C program
  • 58. • 5. Global Declarations:  The global declaration section contains global variables, function declaration, and static variables. Variables and functions which are declared in this scope can be used anywhere in the program. • Example: • int num = 18;
  • 59. • 6. Statements/Instructions  Purpose: The core logic of the program, such as input/output, loops, conditions, and function calls.  Example: • printf("Hello, World!n");{ n: Purpose: Inserts a newline in the output.} •
  • 60. • 7. User-Defined Functions (Optional)  Purpose: Define reusable blocks of code to improve modularity and readability.  Syntax: • void display Message() • { • printf("This is a user-defined function.n"); • }
  • 61. • 8. Return Statement  Purpose: End the main() function and optionally return a value to the operating system.  Syntax: • return 0; // Typically used to indicate successful execution
  • 62. •Example of a Simple C Program • #include <stdio.h> // Preprocessor directive • int main() • { • printf("Hello, Worldn"); • } • Output • Hello world •
  • 63. Different stages in converting the c program source code into an executable code •The process of converting C program source code into executable code involves several stages. Here's a breakdown of these stages:
  • 64. Compilation process in c • What is a compilation? • The compilation is a process of converting the source code into object code. It is done with the help of the compiler. The compiler checks the source code for the syntactical or structural errors, and if the source code is error-free, then it generates the object code.
  • 66. • The c compilation process converts the source code taken as input into the object code or machine code. The compilation process can be divided into four steps, i.e., Pre-processing, Compiling, Assembling, and Linking. • The preprocessor takes the source code as an input, and it removes all the comments from the source code. The preprocessor takes the preprocessor directive and interprets it. For example, if <stdio.h>, the directive is available in the program, then the preprocessor interprets the directive and replace this directive with the content of the 'stdio.h' file.
  • 67. • The following are the phases through which program passes before being transformed into an executable form:  Preprocessor  Compiler  Assembler  Linker
  • 68. • 1.Preprocessor • The source code is the code which is written in a text editor and the source code file is given an extension ".c". This source code is first passed to the preprocessor, and then the preprocessor expands this code. After expanding the code, the expanded code is passed to the compiler. • 2.Compiler • The code which is expanded by the preprocessor is passed to the compiler. The compiler converts this code into assembly code. Or we can say that the C compiler converts the pre-processed code into assembly code.
  • 69. • 3.Assembler • The assembly code is converted into object code by using an assembler. The name of the object file generated by the assembler is the same as the source file. The extension of the object file in DOS is '.obj,' and in UNIX, the extension is 'o'. If the name of the source file is 'hello.c', then the name of the object file would be 'hello.obj’. • 4.Linker • Mainly, all the programs written in C use library functions. These library functions are pre-compiled, and the object code of these library files is stored with '.lib' (or '.a') extension. The main working of the linker is to combine the object code of library files with the object code of our program.
  • 70. 1.#include <stdio.h> 2.int main() 3.{ 4. printf("Hello javaTpoint"); 5. return 0; 6.}
  • 72. Executing a program written in C-Language involves a series of steps. These are :