0% found this document useful (0 votes)
7 views

cse syllabus

The document serves as an introduction to the C programming language, covering fundamental concepts such as algorithms, flowcharts, pseudocode, and the structure of C programs. It details the steps involved in program development, including writing, compiling, linking, and executing programs, as well as the importance of testing. Additionally, it outlines the basic structure of C programs, including preprocessor commands, functions, and the purpose of comments.

Uploaded by

gamingklye907
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)
7 views

cse syllabus

The document serves as an introduction to the C programming language, covering fundamental concepts such as algorithms, flowcharts, pseudocode, and the structure of C programs. It details the steps involved in program development, including writing, compiling, linking, and executing programs, as well as the importance of testing. Additionally, it outlines the basic structure of C programs, including preprocessor commands, functions, and the purpose of comments.

Uploaded by

gamingklye907
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/ 35

Module-1 Introduction to C

Programming Language

Department of
Computer Science &
Engineering

www.cambridge.edu.in
Algorithm , Flowchart & Pseudocode

What is an Algorithm?
Algorithm is a set of well-defined instructions in sequence to solve a problem.

Qualities of a good algorithm


1. Input and output should be defined precisely.
2. Each step in the algorithm should be clear and unambiguous.
3. Algorithms should be most effective among many different ways to solve a
problem.
4. 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.
Flowchart
A flowchart is a diagrammatic representation of an algorithm. A
flowchart can be helpful for both writing programs and explaining the
program to others.
Main Symbols Used in Flowcharts
Start/End Symbols (Terminal Symbols):
Represented as circles, ovals, or rounded rectangles.
Indicate the beginning and the end of the flowchart.
Arrows:
Show the flow of control.
Illustrate the sequence of instructions.
Processing Step (Activity):
Represented by a rectangle.
Includes instructions like arithmetic operations or data movements.
Input/Output Symbols:
Represented by a parallelogram.
Used to get inputs from users or display results.
Flowchart
Decision Symbol:
Represented by a diamond.
Used to depict Yes/No or True/False decisions, with labeled arrows indicating
the outcomes.

Labeled Connectors:
Represented by a circle with an identifying label.
Used in complex or multi-sheet diagrams to replace arrows and maintain
clarity.
Symbols used in Flowchart

Flowchart
Algorithm Flowchart
Write a C Program to add 2 numbers.

Algorithm
Step 1: [ Initialization ]
Start
Step 2: [ Input 2 no’s from the user ]
Read num1, num2
Step 3: [ Add num1 and num2 and
assign the result to a variable sum ]
Sum = num1 + num2
Step 4: [ Display sum ]
Print Sum
Step 5: [ Finished ]
Stop
Algorithm Flowchart
Write a C Program to find area of circle.

Step 1: [ Initialization ]
Start
Step 2: [ Input radius from the user ]
Read radius
Step 3: [ Compute Area ]
area =PI * radius*radius
Step 4: [ Display Area ]
Print area
Step 5: [ Finished ]
Stop
Algorithm Flowchart

Design and develop a C program to read a year as an input and find whether it is leap year or not.

Step1: [Initialization]
Start
Step2: [Input year]
Read year
Step3:[Check whether
given year is leap year
or not]
if ( ((year%4==0) &&(year%100!=0))||
(year%400 == 0))
Display leap year
else
Display not a leap year
Step 4:[finished]
stop
• How to Find a Leap Year Using C?
• To find whether a year is a leap year or not using a leap year C program, all
you need to do is enter some conditions (mathematical) in the program
code with the help of If… Else statement; Following are the conditions to
check if the given year is a leap year or not:

• The entered year must be divisible by 4


• The entered year must be divisible by 400 but not by 100
• The second condition is used to segregate the century years from leap
years. Century years are the ones with the ’00s in the end, for instance,
1300, 1500, 1400 and likewise. A century year is considered to be a leap
year only if it is evenly divisible by 400. For example, the years 1200, 1600,
and 2000 are all century leap years since these numbers are perfectly
divisible by 400
Pseudocode

Definition: Pseudocode is a simplified, informal high-level description of an


algorithm using structural conventions of a programming language.
Key Points:
Complete Logic: Describes the entire logic of the algorithm.
Human-Readable: Omits non-essential details like variable declarations,
system-specific code, and subroutines.
Language-Agnostic: Should not include keywords from any specific
programming language.
Purpose: Enhances human understanding of the solution.
Usage: Commonly found in textbooks and scientific publications to
outline program structure before coding.
Pseudocode Example: Calculating Price After Adding Sales Tax
Pseudocode:
Read the price of the product.
Read the sales tax rate.
Calculate sales tax = price of the product × sales tax rate.
Calculate total price = price of the product + sales tax.
Print total price.
End.
Variables:
price of the product , sales tax rate
sales tax , total price
How to perform swapping
• Swapping of 2 numbers:
• With third variable:
temp = a;
a=b;
b=temp;
• Without third variable:
a=a+b;
b=a-b;
a=a-b;
Creating and Running Programs

1. Writing and Editing:


Objective: Write the C program using a text editor.
Key Tools: IDEs (e.g., Visual Studio Code, Code::Blocks) or basic text editors
Task: Develop the program logic and write the code.
2. Compiling:
Objective: Convert source code into machine-readable object code.
Key Tools: C compiler (e.g., GCC, Clang).
Task: Check for syntax errors and produce intermediate object files.
3. Linking:
Objective: Combine object code with required libraries.
Key Tools: Linker (often part of the compiler).
Task: Resolve external references and create an executable file.
4. Executing:
Objective: Run the compiled and linked program.
Key Tools: Command-line interface or IDE’s built-in run feature.
Task: Observe the output and test the program.
Creating and Running Programs
Creating and Running Programs

1. Writing and Editing Programs


What is a Text Editor?
Definition: A software tool used to write, edit, and store code and other text data.

Key Features of a Text Editor:


Search Commands:
• Purpose: Quickly locate and replace specific code statements.
• Benefit: Saves time when modifying or debugging code.
Copy and Paste Commands:
• Purpose: Efficiently move or duplicate code blocks.
• Benefit: Enhances productivity by reducing redundant typing.
Formatting Commands:
• Purpose: Set tabs and align code for better readability.
• Benefit: Makes code easier to read and maintain.
Saving Your Work:
•After Writing: Save the program to disk as a source file.
•Next Step: This source file will be used as input for the compiler.
Creating and Running Programs

2. Why Compile? Convert C source code into machine language to create an


executable program.
Compiler Components:
1.Preprocessor:
1. Purpose: Prepares the source code for translation.
2. Tasks:
1.Scans for commands like code libraries and macros.
2.Modifies the code as needed.
3. Output: Creates a translation unit.
2.Translator:
1. Purpose: Converts the translation unit into machine language.
2. Tasks: Translates the code into an object module.
3. Output: Object module (not yet executable).
Final Steps: Object Module: Needs to be linked with other components (like
C standard libraries).
•Executable: The final program, ready to run.
Creating and Running Programs

3. Linking and Executing C Programs


Linking Programs:
•Combining Code: Gathers functions from your code and system libraries
(like I/O and math functions).
•Linker’s Job: Connects everything to create the final executable program.
Executing Programs:
•Loading: The operating system's loader puts the executable into memory.
•Running: The program starts, often with a "run" command.
•During Execution:
• Input: Reads data from user input or files.
• Processing: Performs operations on the data.
• Output: Shows results on-screen or saves to a file.
•Finishing: The program ends, and the operating system removes it from
memory.
Modern IDEs:
•One-Click Run: Linking and execution are combined into a single step.
System Development Life Cycle (SDLC)

Overview:
• SDLC: A systematic approach used in modern software development.
• Waterfall Model: A widely recognized SDLC model with distinct phases
that follow a linear progression.
Phases of the Waterfall Model:
1.Systems Requirements: Define what the proposed system should
accomplish.
2.Analysis: Evaluate different approaches from a systems perspective.
3.Design: Define individual program functions and complete file/database
designs.
4.Coding: Write programs based on design specifications.
5.Testing: Test all programs together to ensure the system works as intended.
6.Maintenance: Maintain and support the system after deployment.
Key Points:
•Iteration: Despite the linear flow, revisiting and reworking earlier phases is
common due to errors or changes.
System Development Life Cycle (SDLC)
Program Development

Program Development is a Multistep Process:

Understand the Problem: Begin by thoroughly analyzing the program


requirements and design interfaces.

Develop a Solution: Plan how to convert given inputs into the specified
outputs. This constitutes the core of program design.

Write the Program: Implement the planned solution in code, ensuring it


meets the defined requirements.

Test the Program: Validate the program through testing to ensure it functions
as expected.
Program Development

Once we fully understand the problem and have clarified any questions, we
proceed to develop our solution. This process is supported by three main
tools:
• structure charts
• pseudocode
• flowcharts.
Typically, we use a structure chart to design the entire program, while either
pseudocode or flowcharts are employed to design its individual parts or
modules.
Structure chart for an Email server
Program Development

1. Structure Chart in C Programming

A Structure Chart in C programming is a diagram that shows the organization of


functions in a program and their relationships. It helps in understanding how a
program is broken down into smaller functions, which interact to perform the
complete task.

Example Structure Chart: C Program to Find the Largest of Three Number

• Main Function: Controls the overall execution.

• Input Function: Reads three numbers from the user.

• Comparison Function: Compares the three numbers to find the largest.

• Output Function: Displays the largest number.


Program Development

START Declare
2. Pseudocode inthree variables: num1, num2, num3 Input num1,
C Programming
num2, num3
Pseudocode in IF
C num1 >= num2
programming AND the
describes num1logic>=
of num3 THEN
a program in alargest =
num1 ELSEhuman-readable
structured, IF num2 >= num1 AND num2
form before >= num3
actual coding. It isTHEN largest
not specific to =
C
num2 ELSE
syntax but largest
can = num3
be easily END
translated IF C
into Print "The largest number is"
code.
largest
ExampleENDSTART
Pseudocode: Declare threetovariables:
C Program num1,of
Find the Largest num2,
Threenum3
Numbers

BEGIN
Declare three variables : A, B, C
Input A,B,C //Read three numbers
IF A>=B && A>=C
largest = A
ELSE IF B>=A && B>=C
largest = B
ELSE
largest=C
END IF
Print “ The largest number is “ l
END
Program Development

START Declare
3 Flowchart in Cthree variables: num1, num2, num3 Input num1,
Programming
num2, num3inIFCnum1
A Flowchart >= num2
programming ANDrepresents
visually num1 >=the num3
logic THEN
of a C largest
program=
num1 ELSE IF symbols
using standard num2 >= num1various
to depict AND num2 >= num3
operations THEN
and flow largest =
of control.
num2
Example ELSE largest =Cnum3
Flowchart: END
Program toIFFind
Printthe
"The largest
Largest number
of Three is"
Numbers
largest ENDSTART Declare three variables: num1, num2, num3
Program Development

START Declare three variables: num1, num2, num3 Input num1,


num2,
Types ofnum3 IF Testing:
Software num1 1. >=Blackbox
num2 Testing
AND num1 >= num3
2. Whitebox TestingTHEN largest =
num1 ELSE IF num2 >= num1 AND num2 >= num3 THEN largest =
num2 ELSE largest
1. Blackbox Testing = num3 END IF Print "The largest number is"
largest ENDSTART Declare three variables: num1, num2, num3
Overview:
•Testing without knowledge of the program's internal workings.
•Focuses on whether the program meets user requirements.

Process:
•Test plans are based on the requirements statement.
•Performed by system test engineers and users.
•Helps ensure the system works as expected.

Importance:
•Reviewing test plans early helps clarify requirements and guide development.
Program Development

START Declare
2. Whitebox three variables: num1, num2, num3 Input num1,
Testing
num2, num3 IF num1 >= num2 AND num1 >= num3 THEN largest =
Overview:
num1 ELSE
•Testing withIFfull
num2 >= num1
knowledge AND
of the num2internal
program's >= num3 THEN largest =
structure.
num2 ELSE by
•Performed largest = num3 END IF Print "The largest number is"
the programmer.
largest ENDSTART Declare three variables: num1, num2, num
3Process:
•Test every instruction and possible scenario.
•Treat the program like a "glass house" where everything is visible.

Tips for Effective Testing:


•Start designing test plans early, ideally during the design stage.
•Use experience to create good test data.
•Identify unusual situations to test as you develop the program.
Basic Structure Of C Programs
Basic Structure Of C Programs

Every C program consists of:


• One or more preprocessor commands
• A global declaration section
• One or more functions
The global declaration section:
• Comes at the beginning of the program
• Is visible to all parts of the program
Functions in a C program:
• Perform the tasks within the program
• One function must be named main
• The main function is the starting point of the program
Basic Structure Of C Programs

Structure of functions:
Divided into two sections:
Declaration section: Describes the data used in the function (local
o

declarations, visible only within the function)


o Statement section: Contains instructions for the computer, written as

statements
Preprocessor commands:
Special instructions to the preprocessor for preparing the program for
o

compilation
o One common preprocessor command is include

The include command:


o Tells the preprocessor to include information from selected libraries
(header files)
o Essential for using library functions in programs, such as i/o operations
Basic Structure Of C Programs
Summary :
Preprocessor Commands
Start at the beginning of the program with #.
Example: #include <stdio.h>
Purpose:
Instructs the compiler to include libraries, e.g., stdio.h for
input/output.
Main Function
Starts with void main( ) / int main( )
int: Returns an integer
void: No parameters
Main Content:
Print Statement: printf("Your message\n");
Termination: return 0;
Delimiters:
Enclosed in { }
Basic Structure Of C Programs

Purpose of Comments
Clarify code, serve as documentation, ignored by the compiler.
Block Comments
Syntax:
• Starts with /*, end with */
• Spans multiple lines
Example:
/*
Name of Program:
Date:
Description:
*/
Line Comments
Syntax:
•Start with //
•For single-line comments
•Example:

// This is single line comment


Lab 1 :Write a C Program to do the following
1) To add two numbers
2) To find simple interest
3) To find the area of a circle
4) To convert temperature into Fahrenheit [F = (c*1.8) + 32] and vice-versa
5) To swap two numbers with third variable
6) To swap two numbers without third variable
7) To find if the year is leap year or not
8) To find whether the number is even or not
9) To check if the number is divisible by 2
10) To find the greatest of 2 numbers
11) To find largest of 3 numbers
12) To check if the number is positive or negative
13) To check if a person is eligible for voting (greater than or equal to 18 years)
14) To print your name on screen
15) To print ASCII value of a character (eg: A = 65)

You might also like