Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 53

Problem Solving Using C Programming

ECE/ECM
Defining the Software Development Process

Unit-1
Introduction
COURSE OBJECTIVES:
The objectives of this course are:
1.       Provide exposure to problem solving through C programming
2.       Explore the structure and syntax of C programming language
3.       illustrate the applications of data types, operators, arrays, and control flow
statements in problem solving.
4.       Demonstrate the usage of procedure-oriented programming.
5.       Provide insight into concepts like pointers, structures, and unions
INTRODUCTION

1. COURSE OBJECTIVES:
The objectives of this course are:
1.       Provide exposure to problem solving through C programming
2.       Explore the structure and syntax of C programming language
3.       illustrate the applications of data types, operators, arrays, and control flow
statements in problem solving.
a.       Demonstrate the usage of procedure-oriented programming.
b.       Provide insight into concepts like pointers, structures, and unions

4
INTRODUCTION

 C is a general purpose language which is very closely associated


with UNIX for which it was developed in Bell Laboratories.
 Most of the programs of UNIX are written and run with the help of 'C'.
 Many of the important ideas of 'c' stem are from BCPL by Martin Richards.
 In 1972, Dennies Ritchie at Bell Laboratories wrote C Language which caused a
revolution in computing world .
 From beginning C was intended to be useful for busy programmers to get things
done easily because C is powerful,dominant and supple language

5
WHY NAME 'C' WAS GIVEN TO THIS
LANGUAGE?

Many of the ideas of C language were derived and taken from 'B' language.
BCPL and CPL are previous versions of 'B' language.
As many features came from B it was named as 'C

6
FEATURES OF C
o C is a structured programming language
o C supports functions that enables easy maintainability of code, by

1.breaking large file into smaller modules


o Comments in C provides easy readability
o C is a powerful language.
o C programs built from
• Variable and type declarations
• Functions
• Statements
• Expressions
7
ALGORITHMS AND FLOWCHARTS
A typical programming task can be divided into two phases:
Problem solving phase
produce an ordered sequence of steps that describe solution of problem
this sequence of steps is called an algorithm

Implementation phase
implement the program in some programming language

8
STEPS IN PROBLEM SOLVING
First produce a general algorithm (one can use pseudo code)

Refine the algorithm successively to get step by step detailed algorithm


that is very close to a computer language.

Pseudo code is an artificial and informal language that helps


programmers develop algorithms. Pseudo code is very similar to
everyday English.

9
PSEUDOCODE & ALGORITHM
o Example 1: Write an algorithm to determine a student’s final grade and indicate whether it is
passing or failing. The final grade is calculated as the average of four marks
Pseudo code:
Input a set of 4 marks

Calculate their average by summing and dividing by 4

if average is below 50 Print “FAIL”


Else
Print “PASS”

10
DETAILED ALGORITHM

1.Step 1: Input M1,M2,M3,M4


2.Step 2:
GRADE (M1+M2+M3+M4)/4
3.Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif

11
THE FLOWCHART
 (Dictionary) A schematic representation of a sequence of operations, as in a manufacturing
process or computer program.

 (Technical) A graphical representation of the sequence of operations in an information system or


program. Information system flowcharts show how data flows from source documents through the
computer to final distribution to users. Program flowcharts show the sequence of instructions in a
single program or subroutine. Different symbols are used to draw each type of flowchart

12
PSEUDOCODE & ALGORITHM
1.A Flowchart
⚫ shows logic of an algorithm

⚫ emphasizes individual steps and their interconnections

⚫ e.g. control flow from one action to the next

13
ALGORITHM
1. Algorithm is a step – by – step procedure which is helpful in solving a
problem. If, it is written in English like sentences then, it is called as
‘PSEUDO CODE’.
Properties of an Algorithm
2. An algorithm must possess the following five properties −
• Input
• Output
• Finiteness
• Definiteness
• Effectiveness

14
EXAMPLE

1. Algorithm for finding the average of three numbers is as follows −


• Start
• Read 3 numbers a,b,c
• Compute sum = a+b+c
• Compute average = sum/3
• Print average value
• Stop

15
16
17
18
FLOWCHART SYMBOLS

Basic
Name Symbol Use in Flowchart

Oval Denotes the beginning or end of the program

Parallelogram Denotes an input operation

Rectangle Denotes a process to be carried out


e.g. addition, subtraction, division etc.

Diamond Denotes a decision (or branch) to be made. The


program should continue along one of two
routes. (e.g. IF/THEN/ELSE)

Hybrid Denotes an output operation

Flow line Denotes the direction of logic flow in the program


STRUCTURE OF “C” PROGRAMS

 Before going and reading the structure of C programs we need to have


a basic knowledge of the following:

1. C's Character Set

2. C's Keywords

3. The General Structure of a 'C' Program

4. How To End A Statement

5. Free Format Language

6. Header Files & Library Functions


20
C'S CHARACTER SET
1. C does not use every character set and key found on
2.modern computers . The only characters that C - Language uses for its programs are
as follows:
 A-Z all alphabets
 a-z all alphabets
 0-9
 # % & ! _ {} [] () $$$$ &&&& |
 space . , : ; ' $ "
1.+ - / * =

21
THE KEYWORDS

 "Keywords" are words that have special meaning to the C compiler.

 Their meaning cannot be changed at any instance.

 Serve as basic building blocks for program statements.

 All keywords are written in only lowercase.

22
Basic Structure Of “C” Programs

#include<stdio.h>
Header Files
#include<conio.h>
Entry Point Of
Program
void main()
Indicates Starting
{ of Program

-- other statements
}
HEADER FILES

 The files that are specified in the include section is called as Header File.

 These are precompiled files that has some functions defined in them.

 We can call those functions in our program by supplying parameters.

 Header file is given an extension .h .

 C Source file is given an extension .c .

24
MAIN FUNCTION

 This is the “Entry Point” of a program.

 When a file is executed, the start point is the main function.

 From main function the flow goes as per the programmers choice.

 There may or may not be other functions written by user in a program.

 Main function is compulsory for any C program.

25
RUNNING A ‘C’ PROGRAM

 Type a program.

 Save it.

 Compile the program – This will generate an .exe file (executable)

 Run the program (Actually the exe created out of compilation will run and not
the .c file)
 In different compiler we have different option for compiling and running.

26
RUNNING A ‘C’ PROGRAM

 Type a program.

 Save it.

 Compile the program – This will generate an .exe file (executable)

 Run the program (Actually the exe created out of compilation will run and not
the .c file)
 In different compiler we have different option for compiling and running.

27
“C” language TOKENS
 The smallest individual units in a C program are known
as tokens. In a C source program, the basic element
recognized by the compiler is the "token." A token is source-
program text that the compiler does not break down into
component elements.
 C has 6 different types of tokens viz.
1. Keywords [e.g. float, int, while]
2.Identifiers [e.g. main, amount] 3.
Constants [e.g. -25.6, 100]
4. Strings [e.g. “SMIT”, “year”] Strin
gs

5. Special Symbols [e.g. {, }, [, ]


]
6.C Operators
 - programs[e.g.
are +, -, *] using these tokens and the general
written
syntax.
Keywords in Ansi “C”

auto double register switch


break else return typedef
case enum short union
char etern signed unsigned
const float sizeof void
continue for static volatile
default goto struct while
do if int long
The Identifiers
 They are programmer-chosen names to represent parts of the
program: variables, functions, etc.
 Cannot use C keywords as identifiers
 Must begin with alpha character or _, followed by alpha,
numeric, or _
 Upper- and lower-case characters are important (case-
sensitive)
 Must consist of only letters, digits or underscore ( _ ).
 Only first 31 characters are significant.
 Must NOT contain spaces ( ).
Click icon to add image Click icon to add image

31
Click icon to add image Click icon to add image

32
33
34
35
36
Click icon to add image

37
Click icon to add image

38
39
40
41
42
Click icon to add bar Graph

43
Click icon to add bar Graph

44
Click icon to add chart

45
Click icon to add chart

46
47
48
Click icon to add image
Icons
Architecture Commerce Legal Studies Arts & Humanities

Performing Arts Management Studies Science & Tech Engineering

You might also like