Professional Documents
Culture Documents
BY AMIT PATEL
Unit 1
OR
OR
A set of instructions that directs a computer's hardware to perform a task is called a program, or
software program.
Languages that programmers use to write program are called “Programming languages."
OR
Set of commands, instructions, and other syntax use to create a software program
Programming language like C, C++, Java is known as High level programming lanaguage .
In simply, all this language write programming statement in English which is human
understand. And those language understand by user is known “High level programming
language”
What is Programming Language?
It is simple and easy to learn and provides lots of high-level data structures.
Python's syntax and dynamic typing with its interpreted nature make it an ideal language for
scripting and rapid application development.
Parameter High Level Language Low Level Language
Ease of Learning Easy to understand and learn Hard to understand and learn
It cannot be compiled.
Object code is the language that a central processing unit can understand.
It has been translated by the compiler from the programming source code.
Extension : “.obj”
Extension: .exe
Executable Code means a form of computer program or portion which can be executed by
a computer without further translation or modification.
A sequence of statements in binary that is The output of a linker after it processes the
generated after compiling the source object code
program.
Cannot run directly by the CPU. Executable code can be run directly by CPU
There are basically three steps involved in converting your ideas into what is to be done to
make it a working program. There are three steps involved in converting your idea of what
is to be done to a working program.
1. Creating a source code.
Before starting any work , we have to plan or design how to complete it.
NOTE:
Clear and Unambiguous: Algorithm should be clear and unambiguous. Each of its steps
should be clear in all aspects and must lead to only one meaning.
Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it
should be well-defined as well.
Finiteness: The algorithm must be finite, i.e. it should not end up in an infinite loops or
similar.
Algorithm Characteristics
Feasible: The algorithm must be simple, generic and practical, such that it can be executed
upon will the available resources. It must not contain some future technology, or anything.
Step 1 : START
Step 2 : Take an element X
Step 3 : Store your name in X
Step 4 : Print / Display X
Step 5 : STOP
Write an Algorithm to print addition of two numbers.
Step 1 : START
Step 2 : Declare a=10 and Declare b=10
Step 3 : Calculate c = a+b
Step 4 : Display c
Step 5 : STOP
Write an Algorithm to print cube of number.
Step 1 : START
Step 2 : Declare a=10 OR read value of a.
Step 3 : Calculate c = a*a*a
Step 4 : Display c
Step 5 : STOP
Write an algorithm to print 12th marksheet
Step 1 : START
Step 2 : Declare name=“VTCBB” and seatnum=“20BCA151”
Step 3 : Declare cs=90,maths=99,ic=90,cppm=36,dma=90
Step 4 : Display name, Seatnum
Step 5 : Display cs,maths,ic,cppm,dma
Step 6 : Calculate t=cs+maths+ic+cppm+dma
Step 7 : Calculate per=t/5 or t*100/500
Step 8 : Display t and per.
Step 9 : Stop
Write an algorithm to print 12th marksheet
Step 1 : START
Step 2 : Declare variable name, seatnum, cs, maths, ic, cppm, dma
Step 3 : Read all variable value.
Step 4 : Display name, Seatnum
Step 5 : Display cs,maths,ic,cppm,dma
Step 6 : Calculate t=cs+maths+ic+cppm+dma
Step 7 : Calculate per=t/5 or t*100/500
Step 8 : Display t and per.
Step 9 : Stop
Flowchart
Flowcharts normally use standard symbols to represent the different types of instructions.
These symbols are used to construct the flowchart and show the step-by-step solution to
the problem.
Flowchart : Advantages
Communication : Flowchart are better way of communicating the logic of the system
Effective analysis: With the help of flowchart, a problem can be analyzed in a more effective way.
Efficient Coding: The flowchart act as a guide or blue print during the system analysis and
program development phase.
Proper debugging : The flowchart helps in debugging process. Debugging means finding and
correcting problems or mistakes or errors.
Proper documentation: A flowchart serves as a good program documentation which is needed
for future purpose.
Efficient program maintenance: Using the flowchart, we can easily manage the program or a
system.
Flowchart : Disadvantages
START
TAKE A BOWL
STOP
Draw a flowchart to print a square of number
START
DECLARE A=10
CALCULATE
C=A*A
DISPLAY C
STOP
WRITE AN ALGORITHM, FLOWCHART, SAMPLE CALCULATION TO FIND MINIMUM OF TWO
NUMBERS
STEP 1 : START
STEP 2 : DISPLAY “ENTER VALUE OF A”
STEP 3 : READ A
STEP 4 : DISPLAY “ENTER VALUE OF B”
STEP 5 : READ B
STEP 6 : IF A<B THEN GO TO STEP 7 ELSE GO TO STEP 8
STEP 7 : DISPLAY “A IS MINIMUM”
STEP 8 : DISPLAY “B IS MINIMUM”
STEP 9 : STOP
WRITE AN ALGORITHM, FLOWCHART, SAMPLE CALCULATION TO FIND MINIMUM OF TWO
NUMBERS
START
DISPLAY “ENTER
VALUE OF A: “
READ A
DISPLAY “ENTER
VALUE OF B : “
READ B
A
A
TRUE / FALSE /
IS A<B?
YES NO
DISPLAY “A IS DISPLAY “B IS
MINIMUM” MINIMUM”
STOP
Concept of Structure Programming Language
It means that the code will execute the instruction by instruction one after the other.
It doesn’t support the possibility of jumping from one instruction to some other with the help of
any statement like GOTO, etc. Therefore, the instructions in this approach will be executed in a
serial and structured manner.
In C language, all these six sections together make up the Basic Structure
of C Program.
Link Section
Definition Section
main()
Declaration Section
Executable part
Subprogram section
Function 1
Function 2
.Function n
Continue…
The Documentation Section consists of a set of comment lines giving the name of the program
and other details. The compiler ignores the comments and does not print them on the screen.
The Link Section: We declare all the Header Files that are used in our program. From the link
section, we instruct the compiler to link those header files from the system libraries, which we
have declared in the link section in our program.
The Definition Section defines all symbolic constants. Like #define PI 3.14
Continue…
The Global Declaration Section: Within the Global Declarations Section section, we declare
such variables which we can use anywhere in our program, and that variable is called Global
Variables, we can use these variables in any function.
main() function: Every C program must have one main function section. Whenever we create a
program in C language, there is one main() function in that program. The main () function starts
with curly brackets and also ends with curly brackets. In the main () function, we write our
statements.This section contains two parts, declaration and executable part.
Continue…
Declaration Part declares all the variables used in the executable part.
There should be at least one statement in the executable part which contains instructions to
perform certain task.
/* Date -: 27/12/2020
Description -: A Program to find Area of Circle In C Language */
#include<stdio.h> // Link Section
#define PI 3.14 // Definition Section
float r; // Global Declarations Section
int main(void) // Main functions Section
{
float aoc; // Declaration Part
printf("Enter the radius of circle"); // Execution Part
scanf("%f",&r);
aoc=PI*r*r;
printf("area of circle is %f",aoc);
return (0);
}
Token
For example, we cannot create a sentence without using words; similarly, we cannot
create a program in C without using tokens in C.
Therefore, we can say that tokens in C is the building block or the basic component for
creating a program in C language.
Comment
Ignore by compiler.
Used : To provide information about lines of code and for documenting code.
Rules:
First character must be alphabets or underscore.
Must be consists letters, digits and underscore.
Only 31 characters are significant.
Cannot use keyword.
Must not contain white space.
Identifier
Example:
stud
tot
stud_name
per
String
Example:
“VNSGU”
“vnsgu.ac.in”
Special Symbol
void main()
Constants are those whose values {
will not change during program const int a=10;
executions. const float pi=3.14;
clrscr();
Also known as literals.
a=20;
To declare constant ‘const’ pi=31.4;
Decimal points, black spaces, commas cannot be included within an integer constants.
Consist: any combination of numbers between 0 to 7. 4725 does not starts with 0
01491 invalid digit(9)
Base value : 8.
012.23 invalid character(.)
Valid Octal integer Constants : 0, 012,075,0456 051-43 invalid character(-)
Integer Constant: Hexadecimal Integer Constant
Consist: any combination of numbers between 0 to 9 and 4725 does not starts with 0x
a to f or A to F. Here A to F denotes 0 to 15. 0x1H91 invalid charcter(H)
0x12.23 invalid character(.)
Base value : 16.
0x51-43 invalid character(-)
Valid Octal integer Constants : 0x, 0x12,0x8A6,
0x4a84b4
Floating Point Constant
A normal decimal point value will be treated as double until a suffix f is added to the decimal point
value.
Decimal point value using double will be more accurate than float.
Adding suffix l or L to the Decimal point value will be treated as long double.
Valid : 45.28,28.7,0.4
Invalid: 47,05
Floating Point Constant
A floating point constant with an exponent is essentially the same as scientific notation, except that
base 10 is replaced by e or E.
Exponential notation is useful in representing the numbers whose magnitudes are very large or very
small.
For example: 4.1 × 103 is the decimal scientific notation for 4100.
Character constant also represented with a single digit or a single special character or white space
enclosed within a single quotes.
All PC make use of ASCII(American Standard Code for Information Interchange) character set,
where each integer character is numerically encoded.
The Characters may consists of letters, digits, escape sequences and spaces.
Variable are those value which can change during programming execution.
It is a logical name given to the space in memory which contain some changeable value.
Once data is stored with a variable name, it can be retrieved by its variable name for various
computations in a C program.
Purpose :
Different operations can be performed using data stored in variables during program execution
Such operetions are Addition, Subtraction, Multiplication etc
A data can be accessed later in the program by simply referring the name of the variable.
Example : int a;
The number is 25
The Number is 47
Data type
The C language has a rich set of data types to handle different kind of data entered by
programmer.
Basically a data type informs compiler about how much memory a declared variable
required to store input.
Data types are used extensively for declaring variables and functions of different types.
Character Type
Characters stored in 8 bits or 1 byte of memory and the character can also be signed and
unsigned.
Example:
char ch=’a’;
printf(“size of character %lu”,sizeof(ch))
NOTE : Character Type
Signed and unsigned char both used to store single character as per their ASCII values.
For example, ‘A’ will be stored as 65. we don’t need to specify keyword ‘signed’ for using signed
char.
ASCII table contains 128 character values from 0 to 127 and the remaining 127 characters is
known as extended ASCII character set.
In signed character extended set takes value from -128 to -1 whereas in unsigned char it takes
value from 128 to 255.
And when you try to give value 128 to signed char, it will take -128 value like clockwise.
Integer Type
Any operations involving a number out of this range will return either garbage or an error.
Integer Type
Unsigned int
Long
The long type is 4 bytes on 32-bit systems and of 8 bytes in 64-bit setups.
Unsigned long
In some case, we require only positive numeric values; then it’s better to use the unsigned type.
It not only makes sure that you get one but also enhances the range.
This datatype is also numeric but allows numbers with decimal places.
It gives it an ability to store more numerals after the decimal places, double to be exact.
void main();
Every function return one or no value.
Here main function return no any value so we define “void” as return value.
NOTE:
Assigning a value which is more than its upper limit is called overflow.
For example When we try to store float value into integer type variable overflow should be
happen. Because integer variable occupy 2 B and we try to store 4B float data into it.
To resolve this situation, we have to use type casting (Explicit Type Conversion).
Data Underflow
Assigning a value which is less than its lower limit is called overflow.
For example When we try to store integer value into float type variable underflow should be
happen. Because integer variable require 2 B and we have 4B float variable. So after storing
value space is remaining.
To resolve this situation, we have to use type conversion (Implicit Type Conversion).
Type Conversion
Definition: In C, When you convert the data type of a variable to another data type then this
technique is known as “Type Conversion”.
It is done by automatically when we store small data type value into larger data type variable.
‘C’ permits to convert low range data type to high range data types.
‘C’ permits to convert higher range data type to smaller range data types.
In Explicit type casting, you have to force the conversion between data types.
Here data type name define data type in which we want to convert value.
Then the float type variable is converted to int data type through explicit type casting.
And then it is being added.
With this, you can take advantage of features like type representations and hierarchies.
In-Built Type Casting Function
atof() Used for converting the string data type into float data type.
atoi() Used for converting the string data type into int data type.
Compilation and Execution of C Program
Create program.
To start debugging, first decide which variables value you want to see during step by step
execution of program.