0% found this document useful (0 votes)
11 views7 pages

CS25C01 Computer Programming C

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

CS25C01 Computer Programming C

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

CS25C01 Computer Programming C

Introduction to C: Problem Solving, Problem Analysis Chart, Developing an


Algorithm, Flowchart and Pseudocode, program structure, Compilation &
Execution process, Interactive and Script mode, Comments, Indentation, Error
messages, Primitive data types, Constants, Variables, Reserved words, Arithmetic,
Relational, Logical, Bitwise, Assignment, Conditional operators, Input/Output
Functions, Built-in Functions.
Practical: Create Problem Analysis Charts, Flowcharts and Pseudocode for simple
C programs (Minimum three).
Computer Programming

Computer programming is the process of designing,writing,testing and maintaining


instructions in a programming language.so that a computer can perform specific tasks.

Why Computer Programming?

1. Communication – It allows humans to communicate with computers using a formal


language.
2. Automation – Helps automate repetitive and complex tasks.
3. Problem Solving – Implements algorithms to solve real-world problems efficiently.
4. Software Development – Used to create applications, operating systems, and tools.
5. Flexibility – Provides control over how a computer performs tasks.
6. Innovation – Essential for advanced fields like AI, Data Science, Robotics, and Cyber
security.

Real-Time Example of Programming

ATM Machine
● When you insert your ATM card, the machine asks for a PIN, checks your account, and
dispenses cash.
● All these steps are controlled by a program written in a programming language (like
C, Java, or Python in the backend).

Google Maps, washing machines, online shopping , Microwave Oven etc

Computer programming in C
Before C , Machine Language → Assembly → High-level languages like FORTRAN,
COBOL, ALGOL, and B language.

C Programming

● C is a high-level, structured programming language developed by Dennis Ritchie in


1972 at Bell Labs.
● It is often called the “mother of all languages” because many modern languages (like
C++, Java and Python) are influenced by C.
● It is a structured language

● It is top down approach

Why C for Programming?


● Efficient & Fast – Close to hardware, but easier than assembly.
● Portable – A C program can run on different machines with little or no modification.
● Structured – Supports functions, making programs modular and easy to debug.
● Foundation – Helps in learning other languages and understanding system-level
programming.
Steps in C Programming:
1. Problem definition

2. Algorithm/Flowchart

3. Writing code (.c file)

4. Compilation

5. Linking

6. Execution

7. Testing & Debugging

8. Documentation

Example Program (C Programming Basics)

#include <stdio.h> // Header file

int main() {
printf("Hello, World!"); // Output statement
return 0; // End of program
}
Output: Hello,World!

Applications of C Programming
● Operating Systems (e.g., parts of UNIX, Linux, Windows).
● Embedded Systems (like microcontrollers).
● Compilers and Interpreters.
● Database systems (e.g., Oracle).
● Game development.
Problem Solving
Problem solving is the process of analyzing a problem and then writing a C program to
get the solution.

Steps in Problem Solving using C


1. Problem Definition

o Understand the problem clearly.

o Identify input, process, and output.

o Example: Find the sum of two numbers.

▪ Input: two numbers


▪ Process: add them
▪ Output: result (sum)
2. Algorithm Design

o Write step-by-step instructions for solving the problem.

o Example (Sum of two numbers):

0. Start

1. Read two numbers A and B

2. Compute Sum = A + B

3. Print Sum

4. Stop

Flowchart (Optional)
Draw a diagram using symbols to represent the steps of the algorithm.
Coding in C
Translate the algorithm into a C program.
#include <stdio.h>
int main() {
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum = %d", sum);
return 0;
}
3. Compilation & Execution
Compile the program.
Fix syntax errors if any.
Run the program to get output.
4. Testing & Debugging
Check the program with different inputs.
Correct logical or runtime errors.

Problem Analysis Chart (PAC)


Definition
A Problem Analysis Chart (PAC) is a tool used in problem solving to represent a problem in a
tabular form showing:
● Input (what data is required),
● Process (what operations/steps must be performed), and
● Output (the final result).
It helps programmers to analyze the problem clearly before writing the algorithm and
program

Steps in PAC
1. Identify the input data needed.

2. Decide the process/logic to be applied.

3. Determine the output expected.

4. Represent them in a tabular form.

Advantages of PAC
● Provides a clear understanding of the problem.
● Helps in step-by-step analysis.
● Reduces errors while coding.
● Acts as a bridge between problem statement and program design.

Examples
Sum of Two Numbers
Input Process Output

Add the numbers Sum of two


Two numbers (A,B)
(Sum=A+B) numbers

Largest of Two Numbers Proc


Input ess

Two numbers Compare A and B; If A > B → Largest=A else Largest


(A,B) B number

Developing an Algorithm
An algorithm is a step-by-step procedure or a finite sequence of instructions written in a
simple language to solve a specific problem. Example: A cooking recipe is like an algorithm –
step-by-step instructions to reach a result.

Characteristics of a Good Algorithm


1. Finiteness → Algorithm must terminate after a finite number of steps.
2. Definiteness → Each step must be clear and unambiguous.
3. Input → Algorithm should accept zero or more inputs.
4. Output → Algorithm should produce at least one output.
5. Effectiveness → Steps should be simple enough to be carried out.
Steps
1. Problem Definition
 The first step is to understand the problem clearly.
 Read the problem statement carefully and identify what needs to be solved.
 Decide the scope of the problem — what is required and what is not.
 Example: “Write a program to find the factorial of a number.”
2. Identify Input
● Every problem needs some input data.
● In this step, we specify what data must be given to the program.
● Inputs can be numbers, characters, strings, etc.
● Example: To find factorial, input is a positive integer n.
3. Identify Output
● Define what result is expected from the program.
● The output must be clear and specific.
● Example: For factorial problem, the output is the value of n!.
4. Define the Process / Logic
● This is the core of the algorithm.
● Here we decide the sequence of operations, formulas, and methods needed to transform
the input into the output.
● It may include:
Arithmetic operations
Conditional statements (if/else)
Looping structures (for, while)
Functions or recursion
● Example: For factorial, process = multiply numbers from 1 to n (fact = fact × i).
5. Design the Step-by-Step Solution
● Write the algorithm in simple, precise, unambiguous steps.
● Each step should be written in logical order (using numbering).
● Use pseudocode style (English-like instructions).
● Example:
1. Start
2. Read n
3. fact = 1, i = 1
4. Repeat until i ≤ n
fact = fact × i
i=i+1
5. Print fact
6. Stop
6. Test the Algorithm (Dry Run)
● Check the algorithm with sample inputs to ensure correctness.
● This step helps in identifying errors in logic.
● Example: If n = 5 → algorithm must give output 120
Advantages of Using Algorithms
● Provides a clear step-by-step solution.
● Easy to understand for beginners.
● Helps in developing flowcharts and programs.
● Reduces errors and makes debugging easier.
● Acts as a blueprint for writing C code.
● Example 1: Algorithm to Find the Sum of Two Numbers
● Problem: Write an algorithm to find the sum of two numbers.
Algorithm:
1. Start
2. Read two numbers, a and b
3. Compute sum = a + b
4. Print sum
5. Stop

You might also like