0% found this document useful (0 votes)
313 views105 pages

Fundamentals of Computer Science

Here are the key points about algorithms and flowcharts: - Algorithm is a step-by-step procedure to solve a problem. It takes inputs, processes them and produces outputs. - Flowchart is a graphical representation of an algorithm using defined symbols like rectangles, diamonds, arrows etc. - Flowcharts help visualize the logic and flow of operations in an algorithm. They are used to represent sequential, decision and loop logic structures. - Sequential structure shows the linear step-by-step flow of operations. - Decision structure introduces conditional branching using if/else statements. - Loop structure repeats a set of operations using while, for, do-while loops. - Flowcharts help understand,

Uploaded by

Blacky
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)
313 views105 pages

Fundamentals of Computer Science

Here are the key points about algorithms and flowcharts: - Algorithm is a step-by-step procedure to solve a problem. It takes inputs, processes them and produces outputs. - Flowchart is a graphical representation of an algorithm using defined symbols like rectangles, diamonds, arrows etc. - Flowcharts help visualize the logic and flow of operations in an algorithm. They are used to represent sequential, decision and loop logic structures. - Sequential structure shows the linear step-by-step flow of operations. - Decision structure introduces conditional branching using if/else statements. - Loop structure repeats a set of operations using while, for, do-while loops. - Flowcharts help understand,

Uploaded by

Blacky
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/ 105

Please read this disclaimer before

proceeding:
This document is confidential and intended solely for the educational purpose
of RMK Group of Educational Institutions. If you have received this document
through email in error, please notify the system manager. This document
contains proprietary information and is intended only to the respective group
/ learning community as intended. If you are not the addressee you should
not disseminate, distribute or copy through e-mail. Please notify the sender
immediately by e-mail if you have received this document by mistake and
delete this document from your system. If you are not the intended recipient
you are notified that disclosing, copying, distributing or taking any action in
reliance on the contents of this information is strictly prohibited.
FUNDAMENTALS
OF
COMPUTER SCIENCE

Department : Computer Science


and Business Systems
Batch / Year : 2021– 2025 / I Created
by : Course Coordinator Date :
11.11.2021
Table of
Contents
Course Objectives
Syllabus
Course Outcomes (Cos)
CO-PO Mapping
Prerequisites
Lecture Plan
Activity based learning – Tutorial
problems Lecture notes
Assignments
Part A Q&A (with K level and CO)
Part B Qs (with K level and CO)
List of Supportive online Certification courses
Real time applications
Contents beyond Syllabus
Assessment Schedule
Prescribed Text Books & Reference
Books Mini Project Suggestions
Course
Objectives
FUNDAMENTALS OF COMPUTER SCIENCE LTPC
3024
OBJECTIVES

CO1 - To understand the problem solving concepts


CO2 - To understand syntax and constructs of C Language
CO3 - To develop structured programs using basic programming
constructs CO4 - To understands pointers and arrays in C

CO5 - To understand UNIX system interface


CO6 - To understand and apply programming methods
Syllabu
LTPC
s
FUNDAMENTALS OF COMPUTER SCIENCE
3024

UNIT I GENERAL PROBLEM SOLVING CONCEPTS AND INTRODUCTION TO


C 9
General problem Solving concepts: Algorithm, and Flowchart for problem
solving with Sequential Logic Structure, Decisions and Loops. Imperative
languages: Introduction to imperative language; syntax and constructs of a specific
language (ANSI C). Types Operator and Expressions with discussion of variable
naming and Hungarian Notation: Variable Names, Data Type and Sizes (Little Endian
Big Endian), Constants, Declarations, Arithmetic Operators, Relational Operators,
Logical Operators, Type Conversion, Increment Decrement Operators, Bitwise
Operators, Assignment Operators and Expressions, Precedence and Order of
Evaluation, proper variable naming and Hungarian Notation. Control Flow with
discussion on structured and unstructured programming: Statements and Blocks, If-
Else-If, Switch, Loops – while, do, for, break and continue, goto labels, structured
and un- structured programming.
UNIT II FUNCTION AND PROGRAM STRUCTURES 9
Functions and Program Structure: Basics of functions, parameter passing and
returning type, C main return as integer, External, Auto, Local, Static, Register
Variables, Scope Rules, Block structure, Initialisation, Recursion, Pre-processor,
Standard Library Functions and return types, Standard Library.
UNIT III POINTER AND ARRAYS 9
Pointers and Arrays: Pointers and address, Pointers and Function Arguments,
Pointers and Arrays, Address Arithmetic, character Pointers and Functions, Pointer
Arrays, Pointer to Pointer, Multi-dimensional array and Row/column major formats,
Initialisation of Pointer Arrays, Command line arguments, Pointer to functions.
UNIT IV STRUCTURES AND I/O 9
Structures: Basic Structures, Structures and Functions, Array of structures, Pointer
of structures, Self-referral structures, Table look up, typedef, unions, Bit-fields.
Input and Output: Standard I/O, Formatted Output – printf, Formated Input –
scanf, Variable length argument list, file access including FILE structure, fopen,
stdin, sdtout and stderr, Error Handling including exit, perror and error.h, Line I/O.
UNIT V UNIX SYSTEM INTERFACE AND PRORAMMING METHOD 9
Unix system Interface: File Descriptor, Low level I/O – read and write, open,
create, close and unlink, Random access – lseek, Discussions on Listing Directory,
Storage allocator. Programming Method: Debugging, Macro, User Defined
Header, User Defined Library Function, makefile utility.
TOTAL: 45 PERIODS
Syllabu
LTPC
s
FUNDAMENTALS OF COMPUTER SCIENCE
3024

LIST OF EXPERIMENTS:
1. Algorithm and flowcharts of small problems like GCD
2. Structured code writing with:
i. Small but tricky codes
ii. Proper parameter passing
iii. Command line Arguments
iv. Variable parameter
v. Pointer to functions
vi. User defined header
vii. Make file utility
viii. Multi file program and user defined libraries
ix. Interesting substring matching / searching programs
x. Parsing related assignments
TOTAL: 30 PERIODS
Course
Outcomes
Upon completion of the course, the students will be
able to
Apply problem solving techniques to simple computational
problems K3
Understand the syntax and constructs of C language K1
Develop structured programs using basic constructs in C K3
Understand pointers and arrays in C K2
Understand Unix system interface K1
Apply various programming methods K4
CO – PO/PSO
Mapping

POs/PSOs

COs PO PO PO PO PO PO PO PO PO PO1 PO1 PO1 PS


PSO PSO
1 2 3 4 5 6 7 8 9 0 1 O3
2 1 2

CO1 3 3 3 3 3 1 1 1 2 2 3 3 3 2 2
CO2 3 2 2 2 3 1 1 1 1 2 2 3 3 2 2
CO3 3 2 2 2 3 1 1 1 1 2 2 3 3 2 2
CO4 3 2 2 2 3 1 1 1 1 2 2 3 3 2 2
CO5 3 2 2 2 3 1 1 1 2 2 3 3 3 2 2
C06 3 2 2 2 3 1 1 1 2 2 3 3 3 2 2
Prerequisites
Prerequisites
1. Introduction to Computers

https://drive.google.com/file/d/1LShECakErVJelpHyFzc4X3r8rSrb64dh
/view?usp=sharing

2. Computer Architecture

https://drive.google.com/file/d/1M7I2BTaFkpT1r3sKnq-
C8LIldALq_cSs/view?usp=sharing
UNIT I
GENERAL PROBLEM
SOLVING CONCEPTS
AND INTRODUCTION
TO C
LECTURE PLAN
UNIT – I
Schedule Actual Date
S. No. of Mode of Taxonom
Topic d of CO
No. Periods Delivery y Level
Date Completion
General problem Solving
concepts: Algorithm, and
Video/
1 Flowchart for problem 2 CO1 K1
PPT
solving with Sequential
Logic Structure,
Decisions and Loops.
Imperative languages:
Introduction to
PPT/
2 imperative language; 1 CO1 K1
Demo
syntax and constructs
of a specific language
(ANSI C)
Types Operator and
Expressions with
discussion of variable
naming and Hungarian
PPT/
3 Notation: Variable 2 CO1 K2
Names, Data Type and Demo
Sizes (Little Endian Big
Endian), Constants,
Declarations
Arithmetic
Operators,
Relational
Operators, Logical
Operators, Type
Conversion,
Increment
PPT/
4 Decrement 2 CO1 K3
Operators, Bitwise Demo
Operators,
Assignment
Operators and
Expressions,
Precedence and
Order of Evaluation
Control Flow with
discussion on structured
and unstructured
programming:
Statements and Blocks,
PPT/
5 If-Else-If, Switch, Loops 2 CO1 K2
– while, do, for, break Demo
and continue, goto
labels, structured and
un- structured
programming.
Activity Based
Learning
UNIT – I
Topic Activity

Problem Solving Tutorial Session

Flow Chats Raptor Tool

Operators Questioning

Basic Programming Online Quiz and Debugging


Lecture
Notes
UNIT I GENERAL PROBLEM SOLVING CONCEPTS AND
INTRODUCTION TO C

General problem Solving concepts: Algorithm, and Flowchart for


problem solving with Sequential Logic Structure, Decisions and Loops.
Imperative languages: Introduction to imperative language; syntax
and constructs of a specific language (ANSI C). Types Operator and
Expressions with discussion of variable naming and Hungarian Notation:
Variable Names, Data Type and Sizes (Little Endian Big Endian),
Constants, Declarations, Arithmetic Operators, Relational Operators,
Logical Operators, Type Conversion, Increment Decrement Operators,
Bitwise Operators, Assignment Operators and Expressions, Precedence
and Order of Evaluation, proper variable naming and Hungarian
Notation. Control Flow with discussion on structured and unstructured
programming: Statements and Blocks, If-Else-If, Switch, Loops – while,
do, for, break and continue, goto labels, structured and un- structured
programming.
General Problem
Solving Concepts
Chapter No. 1.1
Algorithm
An algorithm is a well-defined computational procedure consisting of a set
of instructions that takes some value or set of values, as input, and
produces some value or set of values, as output.

An algorithm is a sequence of instructions used to solve a problem.


An algorithm is a step by step procedure for solving any problem. It consists
of finite set of unambiguous rules (instructions) which specify a finite
sequence of operations that provides the solution to a problem.

It is also a precise rule (or set of rules) specifying how to solve a problem.
An algorithm is a sequence of finite instructions, often used for calculation
and data processing.

The word algorithm derives from the name of the mathematician,


Mohammed ibn-Musa al-Khwarizmi, who was part of the royal court in
Baghdad and who lived from about 780 to 850.

Characteristics of Algorithm
The algorithm should be written in sequence.

It looks like normal English.

The result should be obtained only after the algorithm terminates.


The instruction in an algorithm should be repeatedly infinitely.

Each step of an algorithm must be exact.


there
An algorithm must be precisely and unambiguously described, so that
remains no uncertainty.
An algorithm must terminate.
An algorithm must contain a finite number of steps in its execution. An algorithm
must be effective.
An algorithm must provide the correct answer to the
problem. An algorithm must be general.

This means that it must solve every instance of the problem.


Qualities of good algorithm
The following are the primary factors that are used to judge the quality of an
algorithm,
Time
Memory
Accuracy
Sequence

Properties of an Algorithm
An algorithm is not a program, as they cannot be executed by a computer.
It is an ordered sequence of finite, well defined unambiguous instructions
for completing a task.
Steps must be ordered, unambiguous and finite

in number. Ensure that the algorithm has proper

termination.

Effectiveness of each step is very important.


The desired output must be obtained only after the algorithm
terminates. The algorithm should be written in sequence.

There must be no ambiguity in any instruction.


There should not be any uncertainty about which instruction to be executed
next. An algorithm cannot be open ended.

Different algorithms may accomplish the same task, varying in set of


instructions, in time,
space and efforts.
Algorithms can have steps that repeat(iterate) or require decisions(logic and
comparison). Algorithm differs in their requirements of time and space.
For a particular task, different algorithms can be written.
Programmer selects the best suited algorithm for a given task to
be solved. Algorithm has a finite number of inputs.

The algorithm should conclude after a finite number of steps.


Exampl
e
Example #1
Problem Statement : Addition of Two Numbers
Step 1: Start
Step 2: Read A, B
Step 3: Compute C = A + B
Step 4: Print C

Step 5: Stop

Example #2
Problem Statement : Calculate the area & circumference of a
circle

Step 1: Start
Step 2: Read
r

Step 3: Compute area=3.14*r*r


cir=2*3.14*
r Step 4: Print area, cir

Step 5: Stop
Flowchart
Definition: Flowchart is a pictorial representation of an algorithm in which
the steps are drawn in the form of different shapes of boxes and the
logical flow is indicated by interconnecting arrows.

❖ Boxes represent operations


❖Arrows represent the sequence in which the operations are implemented
It helps in understanding the logic of the program.
❖ It is not necessary to include all the required steps in detail.
It outlines the general procedure.
❖ It provides visual representation of the program, So it is valuable.

Guidelines for preparing Flowcharts


❖ The flow chart should be clear, neat and easy to follow
❖ The flowchart must have logical start and finish
❖ In drawing a proper flowchart, all necessary requirements should be listed
in logical order.
❖ Only one flow line should come out from a process symbol.

Or

❖Only one flow line should enter a decision symbol. Two or three flow lines may
leave the decision symbol.
Guidelines for preparing Flowcharts
(Continued…)
Only one flow line should be used with a terminal symbol.
Use annotation symbol to describe data or process more clearly.

Connector symbols are used to reduce the number of flow


lines. Intersection of flow lines must be avoided.
Useful in testing the validity of the flow chart with normal and unusual test data.

Benefits of Flowcharts
Makes Logic Clear:
The pictorial representation helps in understanding the logic clearly.
Assists in finding the key elements of a process by drawing clear flow lines.
Communication: It encourages communication among programmers and
users
Effective Analysis:
It reveals redundant or misplaced steps
It helps in analysing the logic of the program by other persons who may
or may not know programming techniques.
It establishes important areas for monitoring or data collection
It identifies areas for improvement.
Useful in Coding:
It ensures that no steps are missed while coding.
Coding can be done faster.
Proper testing and Debugging:
It helps in detecting errors.
Test the logic with normal/unusual data.
Appropriate Documentation:
It serves as a good program documentation tool.
It helps in knowing what the program does and how to use the program.
Efficient Program Maintenance
The maintenance of operating program becomes easy with the help
of flowchart.
It helps the programmer to put efforts more efficiently on that part.
Limitations
Complex
It is laborious to draw flow chart for larger programs
For large programs it continues to pages making difficult to understand.
Costly
Difficult to Modify
Any changes or modification to a flowchart usually require redrawing
the entire logic again.
It is not easy to draw thousands of flow lines and symbols, especially for
a large complex program.
No update
Usually programs are updated regularly but corresponding update
of flowcharts may not take place, especially in case of large
programs.
As a result, the logic used in the flowchart may not match with the
actual program's logic.

Example for Flowchart


To find the sum of two Find the biggest of two
numbers numbers
Flowchart
Symbols
Building Blocks ofAlgorithms / Problem Solving Aspects:
An algorithm can be constructed from any one of the three basic building
blocks. The building blocks of algorithm are listed below:
Instructions/statement
s State

Control flow
Sequence
Selection /
decision
Repetition / Iteration
Functions

1. Instructions / Statements
Instructions are the statements of actions which are to be performed in
a sequential order.
A statement is a unit of code/instruction that has an effect, like creating
a variable or displaying a value.
Examples:
Example 1: Set your age as 18.
Example 2: Print "RAIDERS ARE CHAMPS" 39 times.
Example 3: If you were born in California, print "NATIVE",
otherwise print "RESIDENT".

2. State of an algorithm
A state provides the value of a variable at a particular instant in time.
Programmers generally choose names for their variables that are
meaningful—
they document what the variable is used for.

Example: For emulating a bus moving along a route, bus_state will be


holding
any one1.ofparked
the following values at different instant of time.
2. moving
3. stopping 4.
loading_unloading
Initially the bus will be in the parking stage (bus_state= parked).Later
when the bus starts, the variablebus_state will be holding the value MOVING
(bus_state= moving).
3. ControlFlow

The three types of control flows


are: Building Block Common name
Sequence Action
Selection Decision
Iteration Repetition or Loop

3.1 Sequence Flow


❖ In sequence construct, statements are executed diagram

one by one in the order from top to bottom.

❖ The actions are performed in the same sequence


(top to bottom) in which they are written.

Example: Accept two numbers and find their product


Algorithm
step1. Input first number as A
step2. Input second number as
B step3. Set Prod=A*B
step4. Print
Prod step5.
Stop

Flowchart
3.2 Selection / Decision Flow diagram
Statements are used when the outcome of the0
process depends on some condition.
A condition in this context may evaluate either
to a true or false value.
The statement will be executed when the

condition becomes true.

If the condition fails, the control shifts out of the


loop to the consecutive statement.

Example: Accept two numbers, Display the first number if greater than
the second.
Algorithm
step1. Start
step2. Accept two numbers and store the variables in A and B.
step3. If (A > B) then Display A is greater than B.
step5. Else Display B is greater than A
step6. Stop

Flowchart
3.3 Repetition Flow diagram
Repetition involves in executing one
or more steps for a number of times.
These statements execute one or more
steps until some condition is true.

Example: Factorial of a given number (Repetition)


Algorithm
Step 1: Start
Step 2: Get the value of
n Step 3: Assign f=1,
i=1
Step 4: check i<=n repeat step 5 and

6 Step 5: calculate f=f*i

Step 6: calculate i=i+1


Step 7: Print the value of f
Step 8: Stop
Flow chart: Factorial of a given number
(Repetition)
Imperative
Languages
Chapter No. 1.2
Introduction to Imperative
Language
Imperative programming is a programming paradigm that uses statements that
change a program's state. In much the same way that the imperative mood in
natural languages expresses commands, an imperative program consists of
commands for the computer to perform. Imperative programming focuses on
describing how a program operates.

Procedural programming is a type of imperative programming in which the program


is built from one or more procedures (also termed subroutines or functions.

History of C
The root of all modern languages is ALGOL, introduced in 1960. ALGOL was the
first computer language to use a block structure.

In 1967, Martin Richards developed a language called BCPL (Basic Combined


Programming Language) primarily for writing system software.

In 1970, Ken Thompson created a language using many features of BCPL and
called it simply B.

C was evolved from ALGOL, BCPL and B by Dennis Ritchie at Bell Laboratories in
1972 and it was known as “traditional C”.

The language became more popular after publication of the book ‘The C
Programming Language’ by Brian Kerningham and Dennis Ritchie in 1978. The
language came to know as “K&R C”.

To assure that the C language remains standard in 1983, American National


Standards Institute (ANSI) appointed a technical committee to define a standard
for C. The committee approved a version of C in 1989 known as ANSI C.

It was then approved by the International Standards Organization (ISO) in 1990.


Features and Application of C
Language
C is a general purpose, structured programming language.

C is a powerful, efficient, compact and flexible.


C is highly portable (i.e., It can be run in different operating systems
environments).

C is a robust language whose rich set of built in functions and operators can be
used to write any complex program.

C has the ability to extend itself. We can continuously add our own functions to
the existing library functions.

C is well suited for writing system software as well as application software.


C program can be run on different operating systems of the different computers
with little or no alteration.

C is a middle level language, i.e. it supports both the low level language and high
level language features.

C language allows reference to a memory allocation with the help of pointers,


which holds the address of the memory location.

C language allows dynamic memory allocation i.e. a program can request the
operating system to allocate or release memory at runtime.

C language allows manipulation of data at the lowest level i.e., bit level
manipulation. This feature is extensively useful in writing system software
program.

C programs are fast and efficient.

C has got rich set of operators.


C can be applied in systems programming areas like Compilers, Interpreters and
Assemblers.
Basic Structure of C
Program: Documentation section
Link section /* pre-processor
directives*/
Definition section

Global Declaration section

main() function section


{
Declaration part
........................................
Executable part
.........................................
}
Subprogram section

(User defined Functions)

Documentation section:
It consists of comment lines giving the name of the program, author & other
details which the programmer would like to use.
Comments are not necessary in the program.
It is useful for documentation.

Comments are non executable statements which are placed between the
delimiters /* */ for multi line comments and started with // for single line
comments.
The complier does not execute comments
Link section:

It provides instruction to the compiler to link functions from the system library.
Program depends upon some header files for function definition that are used in
program.

Each header file by default is extended with .h

The header file should be included using #include directive.

Example : #include<stdio.h> or #include “stdio.h”


In this example <stdio.h> file is included, that is, all the definitions and
prototype of function defined in this file are available in the Current program.

Definition section:

It defines all symbolic constants.

Global declaration section:


The section declares some variables that are used in more than one function.
These variables are known as global variable.

This section must be declared outside of all the functions

Function main
Every program written in C language must contain main() function.

Empty parentheses after main are necessary.

The execution of the program always begins with the function main().

Declaration part:

The declaration part declares the entire variables that are used in executable part.
The initialisations of variables are done in this section. Initialisation means
providing initial value to the variables.
Executable part:
This part contains a set of statements or a single statement.
These statements are enclosed between the braces ({}).

All the statements in the program end with a semicolon.


User- Defined function
The functions defined by the user are called user-defined functions.
These functions are generally defined after the main() function.

They can also be defined before main() function. This portion is not compulsory.

Programming Rules
All statements should be written in lower case letters. Upper case letters are only
used for symbolic constants.
Blank spaces may be inserted between the words.
The program statements can written anywhere between the two braces following
the declaration part.
The opening and closing braces should be balanced. eg., if opening braces are
four, then closing braces should be four.
Sample C Program

Example

#include<stdio.h>
void main()
{
printf(“HELLO”);
}
Character
Set
A character denotes any alphabet, digits, white spaces or special symbol used to
represent information.

Letters A to Z and a to z

Digits 0 to 9

White spaces Blank space, Horizontal tabs,


vertical tab, New line, Form feed.
Special character ,->comma
&->Ampersand
.->period or dot
^->caret
;->semicolon
*->Asterisk
:->colon
- ->minus
“->quotation mark
+ plus
!->Exclamation mark
< less than
| ->vertical bar
> greater than
/->slash etc..
\->back slash
~ ->Tilde
_ ->underscore
$->dollar
?->question mark
Tokens,
Keywords
C Tokens:
The C Language program can contain the individual units called the C
tokens.
The tokens are usually referred as individual text and punctuation in the
text.

C Tokens
are,
Keyword
Identifier
Constants
Operators
Keyword:
The c keywords are reserved words by the
compiler. The keywords cannot be used as variable
name.
All keywords must be written in lower case.
Keywords areauto double
predefined and have standard int struct

meaning continue if volatile break

else long switch default

signed while case enum

register typedef do sizeof

char extern return union

for static const float

short unsigned goto void


Types, Operators
Chapter No. 1.3
Variabl
eA variable is a data name used for storing a data values.
A variable may take different values at different times during the execution.
Variable name may declare based on the meaning of the operation.

Rules
A variable name can be any combination of alphabets, digits and underscore.
Variable should not start with a digit.
The first character must be an alphabet or an underscore ( _ ).

No commas or blank space are allowed within a variable name.

No special symbol can be used in a variable.


Variable Declaration
The variables must be declared before they are used in the program.
Declaration provides two things(1)complier obtain the variable name
(ii)It tells the complier the data type of the variable.

Syntax: Data_ type variableName;


Example: int age;
Variable initializing
Initialization of variable can be done using the assignment operator( =).
The variable can be initialized when it is declared.

Syntax: variableName=constant or data_type variable Name=constant;


Example: int x ; x=2; int y=10;
Types of Variables
Constant Variable:

The value of a certain variable remains the same or remains unchanged during the
execution of a program. It can be done by declaring the variable as a constant.
The keyword const is added before the declaration.
Example: const int m=10;
Volatile Variable
The volatile variables are those variables that are changed at any time by program.
Example: volatile int d;
Basic Data Types
C language provides very few basic datatypes. The datatypes are specified by a
standard keyword. The data types are used to define the type of data for
particular variable. Various data types that are used in C is enlisted in the following
table.

Type Size Range


char 1 byte -127 to 127 or 0 to 255
unsigned 1 byte 0 to 255
signed char 1 byte -127 to 127
int 4 bytes -2147483648 to 2147483647
unsigned int 4 bytes 0 to 4294967295
signed int 4 bytes -2147483648 to 2147483647
short int 2 bytes -32768 to 32767
unsigned short 2 bytes 0 to 65535
int

signed short int 2 bytes -32768 to 32767


long int 4 bytes -21147483647 to 2147483647
signed long int 4 bytes -21147483647 to 2147483647
unsigned long int 4 bytes 0 to 4294967295
float 4 bytes +/-3.4e +/-38
double 8 bytes +/-1.7e +/-308
long double 8 bytes +/-1.7e +/-308

https://www.youtube.com/watch?v=bS6uNMmIoQ
0
Sizes (Little Endian Big
Endian)
Endian:
The term endian refers to the order of storing bytes in computer memory.
Endian

Big Endian Little Endian


Big Endian
In big endian scheme, the most significant byte is stored in the lowest memory
address.
Eg. int a=320;
Little Endian
In little endian scheme, the least significant byte is stored in the lowest memory
address.
Constants:
Constants are identifiers whose value does not change.

Integer type Constant


A constant of integer type consists of a sequence of digits.
Example:
1,34,546,8909 etc. are valid integer constants.
Floating point type constant
Integer numbers are inadequate to express numbers that have a fractional
point. A floating point constant therefore consistent of an integer part, a decimal
point, a fractional part, and an exponent field containing an e or E (e means
exponents) followed by an integer where the fraction part and integer part are a
sequence of digits.
Example:
Floating point numbers are 0.02, -0.23, 123.345, +0.34 etc.
Character Constant
A character constant consists of a single character enclosed in single
quotes. For example, ‘a’, ‘@’ are character constants. In computers, characters are
stored using machine character set using ASCII codes.
String Constant
A string constant is a sequence of characters enclosed in double quotes.
So “a” is not the same as ‘a’. The characters comprising the string constant are stored in
successive memory locations. When a string constant is encountered in a C program,
the compiler records the address of the first character and appends a null character
(‘\0’) to the string to mark the end of the string.
Declaring Constant

#define PI 3.14159
#define service_tax 0.12

Rules for declaring constant


Rule 1: Constant names are usually written in capital letters to visually
distinguish them from other variable names which are normally written in
lower case characters
Rule 2: No blank spaces are permitted in between the # symbol and define
keyword
Rule 3: Blank space must be used between #define and constant name and
constant value
Rule 4: #define is a pre-processor compiler directive and not a statement.
Therefore, it does not end with a semi-colon.
Basic I/O
Statements
FORMATTED INPUT FUNCTION
scanf( )

scanf( ) stands for Scan Formatted.


scanf( ) is used to read all types of data values.

The general syntax is :

scanf(“Conversion symbol”, &variable name);

Example: scanf(“%d”, &a);

scanf() statement reads all types of data values.

It is used for runtime assignment of variables.

Scanf() requires conversion symbol to identify the data to be read during the
execution of a program.
Conversion symbol represents the field format in which the data is to be entered.

Variables should be separated by comma.

Conversion symbol contains the conversion character %, a data type


character and an optional number specifying the field width.

& operator specifies the memory location to store the variable.


The data type character indicates the type of data assigned to the variable.

The format specifiers or conversion symbols used in scanf ()are:


FORMATTED OUTPUT FUNCTION
printf( )
It specifies print formatted and prints all types of data values
It requires conversion symbol and variable names to print the data

The conversion symbol and variable names should be same in

number. The syntax is printf(“Conversion symbol”, variable

name);

Format specifiers or conversion symbol define the format of the values to be


displayed
Escape sequence characters like \n, \t etc, can be used in printf() function.
Example: printf(“%d”, a);
Conversion symbol Description
%d Short integer
%ld Long unsigned integer
%u Short Unsigned integer
%h Short integer
%c Character
%s String
%g Double
%f Float argument
%e same as %f, but use exponential
notation
%o Integer in Octal
Operators:
C provides a rich set of operators to manipulate data. We can divide all the C
operators into the following groups
∙ Arithmetic Operators
∙ Unary Operator
∙ Relational Operators
∙ Logical Operators
∙ Assignment Operator
∙ Bitwise Operators
Arithmetic Operators
The following table list arithmetic operators

Operator Description Example

+ Addition A+B

- Subtraction A-B

* Multiplication A*B

/ Division A/B

% Modulus A%B

/* Example to understand Arithmetic operator */


#include<stdio.h>
#include<conio.h>
void main() Output:
{ a+b=
int a = 10, b=3; 13 a - b =
printf("a + b = ", (a + b) ); 7
printf("a - b = ",(a - b) ); a * b = 30
printf("a * b = ",(a * b) ); a/b=3a
printf("a / b = ",(a / b) ); a% b = 1
printf("a % b = ",(a % b) );
}
Unary Operators

The following are the unary operators

Operator Description Example

+ Unary plus operator +A

- Unary minus operator -A

++ Increment operator ++A or A++

-- Decrement operator --A or A--

++ and - - works in two different modes


i. Pre increment/decrement – When it is part of a statement,
increment/decrement gets evaluated first, followed by the execution of
the statement.
ii. Post increment/decrement – When the operator is part of a statement,

the statement gets processed first, followed by increment/decrement

operation.

// Example for pre increment/decrement

#include<stdio.h>
#include<conio.h>
void main() Output:
{ a++ = 11
int a = 10, b=3;
b-- = 2
printf("a++ = ", (a ++) );
printf("a - - = " , (a - -) );
}
Relational Operators
Relational operators are used to test condition and results true or false
value, The following table lists relational operators

Operator Description Example

== Two values are checked, and if equal, then the condition (A == B)


becomes true
!= Two values are checked to determine whether they are equal or (A != B)
not, and if not equal, then the condition becomes true
> Two values are checked and if the value on the left is greater (A > B)
than the value on the right, then the condition becomes true.
< Two values are checked and if the value on the left is less than (A < B)
the value on the right, then the condition becomes true
>= Two values are checked and if the value on the left is greater
than equal to the value on the right, then the condition becomes (A >= B)
true
<= Two values are checked and if the value on the left is less than (A <= B)
equal to the value on the right, then the condition becomes
true

/* Example to understand Relational operator */

#include<stdio.h>
#include<conio.h>
void main()
Output:
{
int a = 10, b=20; a == b = false
printf("a= = b=", (a ==b) ); a != b = true
printf("a !=b= " , (a!=b) ); a > b = false
printf(“a>b=”,(a>b)); a < b = true
printf(“a>=b=”,(a>=b)); b >= a = true
printf(“a<b=”,(a<b)); b <= a = false
printf(“a<=b=”,(a<=b))
}
Logical Operators
Logical operators are used to combine more than one condition.
The following table lists logical operators

Operator Description Example

This is known as Logical AND & it combines two variables


&& or expressions and if and only if both the operands (A && B) is false
are true, then it will return true
This is known as Logical OR & it combines two variables
|| or expressions and if either one is true or both the (A || B) is true
operands are true, then it will return true
! Called Logical NOT Operator. It reverses the value of a !(A && B) is true
Boolean expression

Example

#include<stdio.h> Output:
void main()
a && b = false
{
boolean a = true; a || b = true
boolean b = false; !(a && b) = true
printf("a && b = " + (a&&b) );
printf("a || b = " + (a||b) );
printf("!(a && b) = " + !(a && b)
);
}

Assignment Operator
Simple Assignment
=, assigns right hand side value to left hand side variable
Ex:
int a;
a = 10;
Compound Assignment
+=, -=, *=, /=, %=, &=, |=, ^=, >>=, <<=, assigns right
hand side value after the computation to left hand side variable

Ex:
int a;
int b;
a += 10; // means a = a + 10;
a &= b; // means a = a & b;

Bitwise Operators

Bitwise operator act on integral operands and perform binary operations. The
lists of bitwise operators are

i. Bitwise AND &


ii. Bitwise OR |
iii. Bitwise EXOR ^
iv. Bitwise NOT ~ (unary operator)
v. Shift Left <<
vi. Shift Ri >>

Bitwise AND

The & operator compares corresponding bits between two numbers and if
both the bits are 1, only then the resultant bit is 1. If either one of the bits
is 0, then the resultant bit is 0.
5-> 0101
9-> 1001
Example : 0001
int x = 5; int y = 9; x & y = 1
Bitwise OR
The | operator will set the resulting bit to 1 if either one of them is 1.
It will return 0 only if both the bits are 0.

Example :
int x = 5; 5-> 0101
int y = 9; 9-> 1001
x | y = 13 1101

Bitwise EXOR
The ^ operator compares two bits to check whether these bits are
different. If they are different, the result is 1.Otherwise, the result is 0.
This operator is also known as XOR operator.

Example :
int x = 5; 5-> 0101
int y = 9;
9-> 1001
x | y = 12
1110

#include<stdio.h>
void main()
{
int x = 5;
int y = 9; Output:
int a = x & y; int b = x | y; int c = x ^ y;
x&y=1
printf("x & y = "+a);
printf(" x | y = "+b); x | y = 13
printf("x ^ y = "+c); x^y=
} 12
Bitwise NOT
The negation ~ operators complements all the bits, 1 are converted to 0
and 0s are converted to 1s.

For Eg.
int a =5;

~a = -5

5 -> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
~5 - > 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0

Shift Operators

The shift operators (<< and >>) shift the bits of a number to the left
or right, resulting in a new number. They are used only on integral
numbers (and not on floating point numbers, i.e. decimals).

Shift Right

The right shift operator(>>) is used to divide a number in the multiples


of 2, while the left shift operator(<<) is used to multiply a number in
the multiples of 2.

For Eg.
int x = 16; x = x >> 3;
right shift operator >>, divides by 2 to the power of number specified
after the operator. In this case, we have 3 as the value after the right
shift operator. So, 16 will be divided by the value 2 to the power of 3,
which is 8.

The result is 2.
When we represent 16 in binary form, we will get the following binary value :
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
When we apply >> which is the right shift operator, bit represented by 1 moves by

the positions to the right (represented by the 3 right shift operator). After

number after the binary digit 1, we will get : shifting

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0

x=2

Shift Left
Eg.
int x = 8;
x = x << 4;
left shift operator <<, multiplies by 2 to the power of number specified
after the operator. In this case, we have 4 as the value after the left shift
operator. So, 8 will be multiplied by the value 2 to the power of 4, which is
16.

The result is 128.


When we represent 8 in binary form, we will get the following binary value:

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
When we apply << which is the left shift operator, bit represented by
1 moves by
the positions to the left (represented by the number right shift 4 After

after the binary digit 1, we will get : operator). shifting

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
X=128

#include<stdio.h>
Output:
Void main()
The original value of x is 8
{ After using << 2, the new value is 2
int x =8; After using >> 4, the new value is 128
printf("The original value of x is “,x);
printf("After using << 2, the new value is “,x << 2);
printf("After using >> 4, the new value is “, x >> 4);
}
PRECEDENCE AND ASSOCIATIVITY OF
OPERATORS
An expression is a combination of constants, variables and operators.

Consider the expression, a + b * c, has higher precedence.

Hence (b*c) will be evaluated first. This result will then be added to a.

In order to override the precedence, parentheses can be used.


Associativity refers to the order in which the operators with the same
precedence are evaluated in expression.

It is also called as grouping.


The operators in an expression are evaluated either from left-to-right or right-to-
left.

In case of nested parentheses, the innermost parentheses are evaluated first.

Expression
An expression is a formula in which operands are linked to each other by the
use of operators to compute a value. An operand can be a function reference, a
variable, an array element or a constant.

Example: x = 9/2 + a-b;


Precedence of
Operators
Proper variable naming and
Hungarian Notation
Hungarian notation is an identifier naming convention in computer
programming, in which the name of a variable or function indicates its intention or
kind, and in some dialects its type.

Hungarian notation was designed to be language-independent


In Hungarian notation, a variable name starts with a group of lower-case letters
which are mnemonics for the type or purpose of that variable, followed by
whatever name the programmer has chosen; this last part is sometimes
distinguished as the given name. The first character of the given name can be
capitalized to separate it from the type indicators
Examples

chInitial : char

nSize : integer

iSize : integer

fpPrice: floating-point

dbPi : double

dwLightYears : double word


Using Hungarian notation, variable names begin with one or more lowercase letters
that denote the variable type, thus providing an inherent identification.
Assignment
Questions

Develop algorithmic solutions


S.No. to simple computational K-Level COs
problems

1. Write algorithm, draw flow chart for K3 CO1


the following three sequential
problems.

i) To Calculate area of circle.

ii) To convert Celsius to Fahrenheit.

iii) To swap two numbers


without using temporary
variable.
2. Write algorithm, draw flow chart for K3 CO1
the following two selection problems.

i)To check the given year is leap year or


not.

ii)To find the given number is


positive, negative or zero.

iii)To find all roots of a quadratic


equation.

3. Write algorithm, draw flow chart for K3 CO1


three iteration problems.

i)To check the given number is


Armstrong number or not
ii)To find the factorial of a given
number
iii) To check the given number is prime
or not.
Control Flow
Statements
Chapter 1.4
Statements and Blocks

An expression such as x=0 or i++ or printf(….) becomes a statement when


it is followed by semicolon.

Example
x=10;
i++;
printf(…..);

Braces { and } are used to group declarations and statements or


block, so that they are syntactically equivalent to a single
statement.

A block statement is generally used to group together several


statements.

Example
Statement blocks

if( i == j)

{
printf(“C Programming \n");
}

The statement block containing the printf is only executed if


the i == j expression evaluates to True.
Decision Making Statement

The statement of C are broadly classified into three categories:

❖ Sequence – Statements are executed one after another.

❖ Selection – Selects the path of execution based on a condition.

❖ Looping – Permits repetitive execution of statements till a condition is satisfied.

Decision Making and Branching

The decision making statement checks the given condition and then executes its sub block.

The decision statement decides the statement to be executed after the success or failure of
a given condition.

Decision making statements are classified into (i) if statement (ii)switch statement

Simple if statement

syntax :

if(Booleanexpressio)

{
statement–block;
}
Next statement;
#includ<stdio.h>
void main()
{
int n=5;
if(n<25)
{
printf(“This is if statement”); Output:
} This is if statement
}

if .. else statement

Syntax

if(boolean expression)
{
True-block statements;
}
else
{
False-block statements;
}
Next statement;
#include<stdio.h>
void main()
{
int age;
printf(“Enter the age”);
scanf(%d”,&age);
if(age>18)
{
printf(“Eligible to vote”);
}
else
{
printf(“Not eligible to vote”);
}
}
Cascading if..else

Syntax:
if (condition1)
{
statement-1
}
….
else if(conditio-n)
{
statement-n
}
else
{
default statement
}
next statement

//program to find largest three number

#include<stdio.h>
void main()
{
int n1,n2,n3;
printf(“Enter the number”);
scanf(“%d%d%d”,&n1,&n2,&n3)
; if(n1>n2 && n1>n3)
{
printf(“%d is largest number”,n1);
}
else If(n2>n3)
{
printf(“%d is the largest number”,n2);
}
else
{
printf(“%d is the largest number”,n3);
}
}
Switch Statement
The switch-case conditional construct is a more structured way of testing
for multiple conditions rather than resorting to a multiple if statement
Syntax:
switch(expression)
{
case 1: case 1 block
break;
case 2: case 2 block
break;
default: default block;
break;
}
statement;

/* This is an example of a switch case statement*/

#include<stdio.h>
Void main()
{
int w;
printf(“Enter the week”);
scanf(“%d”,&w);
switch(w)
{
case 1:
printf(“Sunday”);
break;
case 2:
printf(“Monday”);
break;
case 3:
printf(“Tuesday”)
; break;
case 4:
printf(“Wednesday”);
break;
case 5:
printf(“Thursday”);
break;
case 6:
printf(“Friday”);
break;
/* This is an example of a for loop */

#include<stdio.h>
void main()
{
int i;
for(i=0;i<=5;i++)
{
printf(“i:”,i);
}
Output:
i: 1
i: 2
i: 3
i: 4
i: 5
While Loop

It’s a entry controlled loop, the condition in the while loop is evaluated,
and if the condition is true, the code within the block is executed. This
repeats until the condition becomes false

Syntax

while(condition)

{
Body of the
loop
}

#include<stdio.h>
void main()
/* This is an example for a while loop */
{
int i = 0;
while (i < 5)
{
printf("i: “,i);
i = i + 1;
}
}

Output:
i: 0
I: 1
i: 2
i: 3
i: 4
do.. while Loop
It’s a exit controlled loop, the body of the loop gets executed first
followed by checking the condition. Continues with the body if the condition is
true, else loops gets terminated.

Syntax
do
{
body of the loop
}
while(Boolean expression);

/* This is an example of a do-while loop */

#include<stdio.h>
void main()
{
int i=5;
do
{
println("i: “,i);
i = i + 1;
}
while (i < 5);
}

Output:
I: 5
for Loop

The for loop initialize the value before the first


step. Then checking the condition against the current
value of variable and execute the loop statement and
then perform the step taken for each execution of
loop body. For-loops are also typically used when the
number of iterations is known before entering the
loop.

Syntax

for(initialization;condition; increment/decrement)

Body of the loop

}
/* This is an example of a for loop */

#include<stdio.h>
void main()
{
int i;
for(i=0;i<=5;i++)
{
printf(“i:”,i);
}

Output:
i: 1
i: 2
i: 3
i: 4
i: 5
Break statement
A break statement terminates the loop, and the control then automatically passes
to the first statement after the loop.
Break can be associated with all conditional statements.

Syntactic form :

break;
Program
main( )
{
int num, i; scanf(“%d”, &num); i=2;
while(i<=num-1)
{
if (num%i==0)
{
printf(“The number %d is not a prime number”, num); break;
}

i++;

}
if(i= = num)
printf(“The number %d is a prime number”, num);
}
In this, if num%i=0, then the message not prime number is printed and control
breaks the while loop and the control will reach outside the while loop.

break, breaks the control only from the loop in which it is placed.
The Continue Statement
It is used for continuing next iteration of
loop statements.
When it occurs in the loop, it does not terminate but
skips the statements after this statement.
Write a C program to find the product of 4 integers entered by
a user. If user enters 0 skip it.
//program to demonstrate the working of continue statement in
C programming
# include <stdio.h>
int main()
{
int i,num,product;
for(i=1,product=1;i<=4;++i
)
{
printf("Enter num%d:",i);
scanf("%d",&num);
if(num==0)
continue; / *In this program, when num equals to zero, it skips the
statement product*=num and continue the loop. */
product*=num;
}
printf("product=%d",product); return 0;
}
Output
Enter num1:3
Enter num2:0
Enter num3:5

product = 15
goto Statement:
It is an unconditional branching statement.
This statement does not require any condition.

goto statement passes control anywhere in the program, ie., the control is
transferred to another part of the program without testing any condition.
General Form:
Goto Label;
-
-
Label: Statement;
Label: may be anywhere in the program.
Example:
int main()
{
int age; Vote:
printf("you are eligible for voting"); NoVote:
printf("you are not eligible to vote");

printf("Enter you age:"); scanf("%d", &age); if(age>=18)


goto Vote; else

goto NoVote; return 0;


}
Explanation: In the above example, Vote and NoVote are labels. When the input is >=
18, the goto statement is transferring the control to label – Vote, otherwise it transfers
the control to label-NoVote.
Structured Programming
In structured Programming, the code is divided into functions or modules. It is also
known as modular programming.

Modules are functions are a set of statements which perform a sub task.
As each task is a separate module, it is easy for the programmer to test and debug.

It is also easy to do modifications without changing the whole program.

While changing the code the programmer has to concentrate only on the specific
module.

Eg: C language and Pascal are examples of Structured Programming Language .

Unstructured Programming
Here the codes is written as a single whole block. The whole program is taken as a
single unit. It is harder to do changes in the program. This paradigm was used in earlier
versions of BASIC , COBOL and FPRTRAN.

}
Assignment Questions
CO 1 Develop C program solutions to simple computational problems

1. Write a C program to check whether the number is palindrome number or not K2 CO1
a palindrome number.
Test Data :
Input a three digit number : 121
Expected Output :
The given number is :
121
The given number is palindrome number

2. Write a program in C to calculate factorial of a given number. K2 CO1

Test Data :
Input the given number :5
Expected Output :
The factorial of a given number is : 120
Part A
Question & Answer
Part A
Question & Answer
Part
A
1. Define an algorithm. (CO1)(K2)

An algorithm is a self-contained sequence of actions to be performed. Algorithms


can perform calculation, data processing and automated reasoning tasks. It is an
effective procedure for solving a problem in a finite number of steps.

2. List the characteristics of an algorithm. (CO1)(K2)

Be precise

Be unambiguous

Not even a single instruction must be repeated infinitely.

After the algorithm gets terminated, the desired result must be obtained.

3. What are the qualities of an algorithm? (CO1)(K2)

The following are the primary factors that are used to judge the quality of an
algorithm,
Time

Memory

Accuracy

Sequence

4. List out the ways to represent an algorithm. (CO1)(K2)

Flowchart

Pseudocode

Programming languages
5. What are the various control flow structures in an algorithm? (CO1)(K2)
Sequence

Selection

Repetition

6. What is sequence control flow? (CO1)(K2)


In sequence construct, statements are executed one by one in the order from top to
bottom.

7. What is selection control flow? (CO1)(K2)

Statements are used when the outcome of the process depends on some
condition.

A condition in this context may evaluate either to a true or false value.

8. What is repetition? (CO1)(K2)


It is used to execute a block of code or a part of the program several times.

In other words, it iterates a code or group of code many times.

9. Write the guidelines for preparing flowcharts. (CO1)(K2)


The flow chart should be clear, neat and easy to follow
The flowchart must have logical start and finish

In drawing a proper flowchart, all necessary requirements should be listed in


logical order.
Only one flow line should come out from a process symbol.
Only one flow line should enter a decision symbol. Two or three flow lines may
leave the decision symbol.
Only one flow line should be used with a terminal symbol.
10. Define flowchart. (CO1)(K2)
It is a pictorial representation of an algorithm in which the steps are drawn in the
form of different shapes of boxes and the logical flow is indicated by
interconnecting arrows.
11. Write the advantages of flowchart. (CO1)(K2)
The pictorial representation helps in understanding the logic

clearly. Makes Logic Clear

Assists in finding the key elements of a process by drawing clear flow

lines. It encourages communication among programmers and users

Effective Analysis. It reveals redundant or misplaced steps

12. List the limitations of flowchart. (CO1)(K2)

Difficult to Modify
Cannot be updated frequently
Complex to design for larger
programs Costly

13.List the advantages and disadvantages of iteration. (CO1)(K2)


Advantages
Complexity broken
down
Code
Reusability
Disadvantages

Less
14. What is looping? (CO1)(K2)
Parallelism
Looping is a sequence of instructions that is continually repeated until a certain
condition is reached.
15. Define Problem Solving. (CO1)(K2)
Problem solving means the ability to formulate problems, think creatively about
solutions, and express a solution clearly and accurately.
16. Write an algorithm for interchanging / swapping two values. (CO1)(K2)

Step1: Start
Step2: Read the two numbers as a and

b Step3: set c=a Step4:

set a=b Step5: set

b=c Step6: print a, b

Step7:

Stop
17.Write an algorithm to find whether a number is even or odd. (CO1)(K2)

Step1: Start

Step2: Read a number as A


Step3: if A % 2 == 0 then print “Even”

else print “Odd”

End if

Step4: Stop

18. Write the algorithm to find the average of three numbers. (CO1)(K2)

Step 1: START

Step 2: INPUT a,b,c

Step 3: COMPUTE avg = (a+b+c) / 3


Step 4: PRINT

avg Step 5: STOP


19. Write an algorithm for finding the factorial of a given number.
(CO1)(K2)

Step1: Start
Step2: Read the number.

Step3: Initialize i=1,

fact=1

Step4: Repeat step4 through6 until i<n

Step5: fact=fact*i

Step6: i=i+1 Step7:

print fact Step8: Stop

20. Draw the flow diagram for iteration. (CO1)(K2)

Fals
e

Tru
e
21. What are the Features and Application of C Language? (CO1)(K2)
C is a general purpose, structured programming language.

C is highly portable.
C has the ability to extend itself. We can continuously add our own functions to
the existing library functions.
C is well suited for writing system software as well as application software.

22. What are C Tokens? (CO1)(K2)


The C Language program can contain the individual units called the C tokens.
The tokens are usually referred as individual text and punctuation in the text.

C tokens are classified into (i)Keywords (ii) Identifiers (iii) constant (iv)Operators
(v)String (vi) special characters.

23. Define the rules of Keywords? (CO1)(K2)


The c keywords are reserved words by the
compiler. The keywords cannot be used as variable
name.
All keywords must be written in lower case.

Keywords are predefined and standard meaning

24. Define the rules of Identifiers? (CO1)(K2)


Identifiers contain letters and digits

The first character should be a letter or underscore.


Underscore is the only special character that is allowed in an Identifier.
Length of the identifier is significant up to certain digits depends on the compiler.
Identifiers are case sensitive.

25. List the rules that are to be followed while declaring variable? (CO1)(K2)
A variable name can be any combination of alphabets, digits and underscore.
The first character must be an alphabet or an underscore ( _ ).
No commas or blank space are allowed within a variable name.
No special symbol can be used in a variable.
26. what is variable and write syntax of the variable? (CO1)(K2)
A variable is an identifier.

A variable may take different values at different times during the execution.
Syntax: Data_ type

variableName; Example: int age;

27. Define Constant and voltaile variable? (CO1)(K2)


Constant value of a certain variable remains the same or remains unchanged
during the execution of a program. It can be done by declaring the variable as a
constant.
The keyword const is added before the declaration.
Example: const int m=10;
The volatile variables are those variables that are changed at any time by
program.
Example: volatile int d;
28. List different datatypes in c? (CO1)(K2)
Primitive/ basic datatype
Derived datatype
User defined datatype

29. what are the primitive datatype? (CO1)(K2)


Integer
character
float
double.
Void
30. If a=50,b=10 and c=20 evaluate the following expression. (CO1)(K3)

c+=(a>0&&a<=10)?++a:a/b

c+= (50>0&&50<=10)?++50:50/10
c+=5
c=c+5
c=20+5=25
31. List out the Operators in C? (CO1)(K2)
Arithmetic Operators
Relational operators
Assignment Operators
Logical operators
Bitwise Operators
Conditional or Ternary Operators

Increment and Decrement operators

Special operators

32. Write Syntax of the Conditional operators with example. (CO1)(K2)


Syntax :exp1 ? exp2 :exp3;
Example x = (a>b) ? a : b
Work : exp1 is evaluated first .if it is true , then the expression exp2 is evaluated
and becomes the value of the expression. If exp1 is false, exp3 is evaluated.
33. Find the output for the following (CO1)(K3)

i) 4+8/2*7+4
=4+4*7+4
=4+28+4
=32+4
=36

ii) 4%3*5/2+(5*5)
=4%3*5/2+25
=1*5/2+25
=5/2+25
=2.5+25
=27.5
34.Define formatted input and output functions? (CO1)(K2)
scanf( )

scanf( ) stands for Scan Formatted.


scanf( ) is used to read values in a specified format.

The general syntax is :

int scanf(“Control-String”,

argument_list); Example: scanf(“%d”,

&a);

printf( )
It specifies print formatted and is used to display a message.
The syntax is Printf(“Control-string”, argument-list);
Control string consists of ,
Messages to be printed on the screen.
Format specifiers to define the format for the values to be displayed.
Escape sequence characters like \n, \t etc.
Example: printf(“%d”,a);

35. Explain the typedef datatype? (CO1)(K2)


User to define an identifier that would represent an existing datatype.
Renaming the existing datatype.cannot create new datatype.
Syntax: typedef datatype identifier;
typedef is keyword,datatype is existing datatype,identifier refers to the new
name given to the data type.

Example: typedef int mark;


36. Give the Syntax of switch statement? CO1)(K2)

Syntax of switch statement:

switch(expression)
{
case constant1: block 1;
break;
case constant2: block 2;
break;
......
.....
default: default block;
break;
}

37. Give the Syntax of for loop with an example. CO1)(K2)

Syntax of for loop:

for(initialize counter; test condition; increment/decrement counter)


{
body of the loop;
}

Example: for(i=10;i>=1;i--)
{
printf(“%d”,i);
}
38. Write the syntax of nested if ..else statement.
CO1)(K2)
if(condition 1)
{
if(condition2)
{
True statement1;
}
else
{
False statement 1;
}
}
else
{
False statement2;
}
39. Write the syntax of do..while statement. CO1)(K2)
do
{
Body of the loop;
}while(test condition);
40.. What are all decision control statement in C? (CO1)(K2)

There are 3 types of decision making control statements in C language. They are,
1. if statements
2. if else statements
3. nested if statements

41. What will happen if break statement is not used in switch case in C? (CO1)(K2)
∙ Switch case statements are used to execute only specific case statements
based on the switch expression.
∙ If we do not use break statement at the end of each case, program will execute
all consecutive case statements until it finds next break statement or till the
end of switch case block.

42.What is nested loop? (CO1)(K2)


A nested loop is a loop that runs within another loop. Put it in another sense, you
have an inner loop that is inside an outer loop. In this scenario, the inner loop is
performed a number of times as specified by the outer loop. For each turn on the
outer loop, the inner loop is first performed.

9.. What is the difference between while and do…while loop in C? (CO1)(K2)
∙ While loop is executed only when given condition is true.
∙ Whereas, do-while loop is executed for first time irrespective of the condition.
After executing while loop for first time, then condition is checked.
Part B
Questions
Part B

(CO1) (K2, K3)

1. Explain program development life cycle.

2. Draw & Explain the basic organization of a computer.


3. Draw a flowchart, write an algorithm to find largest of three numbers.

4. Draw a flowchart, write an algorithm to find the factorial of a number.

5. Draw a flowchart, write an algorithm to reverse the given number.

6. Write an algorithm, flowchart to find the sum of first N natural numbers.

7. Write an algorithm, flowchart to display the Fibonacci series.

8. Draw a flowchart, write an algorithm to check the given number is positive,


negative or zero.

9. Write an algorithm, flowchart for 12+22+32+ …..+n2

10. Draw a flowchart, write an algorithm to check the given number is palindrome
or not.

11. Describe the various types of operators with example supported by C.

12. Describe the features of primitive data types and user defined data types in C.

13. Explain the data types and constants supported by C.

14. Write the advantages & disadvantages of using algorithm.

15. Write the advantages & disadvantages of using flowchart.


16. Explain in detail about operator precedence. (CO1)(K2)
17. Illustrate about Conditional statement with example program. (CO1)(K2)
18.. Describe iterative statement with example program. (CO1)(K1)

19. Write a program using for loop to calculate factorial of a number. (CO1)(K1)
20. Write a program to check whether the given number is Armstrong or not.
(CO1)(K3)
21. Write a program to find the sum of a digit. (CO1)(K1)
22. Write a program to find the given number is positive or negative or zero.
(CO1)(K2)
23.Write a program if the word is “Programming in C” display it in reverse manner.
(CO1)(K1)
24.. Write a program to display the month in order using switch case.
(CO1)(K2)
25Write a program to print the following pattern (CO1)(K1).
*
**
***
****

26. Write a menu driven program to find the area of different shapes.
(CO1)(K2)
27. Write a program to find the sum of even number. (CO1)(K3)
Supportive Online
Certification
Certification Courses

NPTEL
Problem solving through Programming in C
https://nptel.ac.in/courses/106/105/106105171/
Coursera
1)C for Everyone: Structured Programming

https://www.coursera.org/learn/c-structured-programmin

2) C for Everyone: Programming Fundamentals


https://www.coursera.org/learn/c-for-everyone
Real time
Applications
Real-Time implementation in C programming

1. Operating Systems
2. Development of New Language
3. Computation Platforms
4. Embedded Systems
5. Graphics and Games
Content beyond
syllabus
Content beyond
syllabus
Problem Solving and Algorithms
Learn a basic process for developing a solution to a problem. This process can
be used to solve a wide variety of problems.

An algorithm development process

Obtain a description of the problem.

Analyze the problem

Develop a high-level algorithm


Refine the algorithm by adding more details

Review the algorithm.


Prescribed Text book &
References
Text books &
References
TEXT BOOK
1. Brian W Kernighan and Dennis M Ritchie, The C
Programming Language, Pearson Education India, 2nd
Edition, 2015.
2. Anita Goel and Ajay Mittal, “Computer Fundamentals and
Programming in C”, Dorling Kindersley (India) Pvt. Ltd.,
Pearson Education in South Asia, 2011.
REFERENCES:
1. B. Gottfried, Programming with C, Schaum Outline Series,
Fourth Edition, 2018
2. Herbert Schildt, C: The Complete Reference, McGraw Hill,
Fourth Edition, 2017
3. Yashavant Kanetkar, Let Us C, BPB Publications, 16th
Edition, 2018.
Mini Project
Suggestions
Mini Projects in C Language

1. Simulate simple calculator


2. Write algorithm, flowchart for placing Amazon order (1.order
placement, 2.payment gateway, 3.goods delivery)

3. Write an algorithm, flowchart for online railway ticket booking


Supportive online
courses
❖ Introduction to Programming in C – Coursera

❖ C for Everyone: Programming Fundamentals – Coursera

❖ C for Everyone: Structured Programming - Coursera

❖ Computational Thinking with Beginning C Programming - Coursera

❖ Problem solving through Programming In C – Swayam

❖ C – Sololearn

❖ C Programming For Beginners – Udemy

❖ C Programming For Beginners - Master the C Language – Udemy

External Links for additional


resources
❖ https://swayam.gov.in/

❖ https://www.coursera.org/

❖ https://www.udemy.com/

❖ https://unacademy.com/

❖ https://www.sololearn.com/

❖ https://www.tutorialspoint.com/cprogramming/index.htm

❖ https://www.w3schools.in/c-tutorial/

❖ https://www.geeksforgeeks.org/c-language-set-1-introduction
/

❖ https://www.programiz.com/c-programming
Real Time
Applications
Content beyond
syllabus
Analysis of algorithms

Analysis of algorithm is the process of analyzing the problem-solving capability


of the algorithm in terms of the time and size required (the size of memory for
storage while implementation). However, the main concern of analysis of
algorithms is the required time or performance. Generally, we perform the
following types of analysis −

Worst-case − The maximum number of steps taken on any instance of size a.

Best-case − The minimum number of steps taken on any instance of size a.

Average case − An average number of steps taken on any instance of size a.

Amortized − A sequence of operations applied to the input of size a averaged

over time.

You might also like