0% found this document useful (0 votes)
69 views120 pages

Quantum PSA

Uploaded by

vinayk4063
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)
69 views120 pages

Quantum PSA

Uploaded by

vinayk4063
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/ 120

2

PUBLISHED BY: Apram Singh CONTENTS


Quantum Publications® BCS101/BCS201:Programming for Problem Solving
(A Unit of Quantum Page Pvt. Ltd.)
-
Plot No, 59/2/7, Site 4, Industrial Area, UNI-1: INTRODUCTION TO COMPUTER SYSTEM (1-1 E to 1-41 E)
Sahibabad, Ghaziabad-201 010 Introduction to Components of a Computer System: Memory,
Processor, I/O Devices, Storage, Operating System, Concept of
Assembler, Compiler, Interpreter, Loader and Linker.
Phone: 0120-4160479 Idea of Algorithm: Representation of Algorithm, Flowchart, Pseudo
Email: [email protected] Website: www.quantumpage.co.in Code with Examples, From Algorithms to Programs, Source Code.
Programming Basics: Structure of C Program, Writing and
Delhi Office M-28, Naveen Shahdara, Delhi-110032
:
Executing the First C Program, Syntax and Logical Erros in
Compilation, Object and Executable Code. Components of C
© QUANTUM PAGE PvT. LTD. Language. Standard I/0 in C, Fundamental Data types, Variables
No part of this publication may be roproduced or transmitted,
and Memory Locations, Storage Classes.
UNIT-2: ARITHMETIC EXPRESSIONS (2-1 E to 2-30 E)
in any form or by any means, without permission.
Arithmetic Expressions and Precedence Operators and Expression
ALL RIGHÍS REŠERVED Using Numeric and Relational Operators, Mixed Operands, Type
Conversion, Logical Operators, Bit Operations, Assignment Operator,
Operator precedence and Associatively.
Information contained in this work is derived from sources
Conditional Branching: Applýing if and Switch Statements, Nesting
believed to be reliable. Every effort has been made to ensure if and Else and Switch.
accuracy, however neither the publisher nor the authors UNIT-3: ITERATION LOOPS
&
(3-1 E to3-39 E)
guarantee the accuracy or completeness of any information Iteration and Loops :-Use of While, do While and for Loops, Multiple
published herein, and neither the publisher nor the authors Loop Variables, Use of Break, Goto and Continue Statements.
shall be responsible for any errors, omissions, or damages Arrays : Array Notation and Representation, Manipulating Array
Elements, using MultiDimensional Arrays. Character Arrays and
arising out of úse of this information. Strings, Structure, union, Enumerated Data types, Array of
Structures, Passing Arrays to Functions.
Programming for Problem Solving (Sem-1 & 2) UNIT-4 : FUNCTIONS (4-1 Eto 4-27 E)
:
1* Edition 2009-10 12thEdition : 2021-22 Functions: Introduction, Types, of Functions, Fuñctions with Array,
2nd Edition 2010-11 13thEdition : 2022-23 Passing Parameters to Functions, Call by Value, Call by Reference,
3rd Edition : 20l1-12 (Thoroughly Revised Edition) Recursiýe Functions.
searching and Sorting Algorithms Searching & Sorting
:

Basic of
4th Edition : 2012-13 14th Edition :2023-24
5th Edition : 2013-14
Algorithms (Linear Search, Binary search, Bubble Sort, Insertion and
Selection Sort).
6th Edition : 2014-15
7th Edition : 2015-16 UNIT-5: POINTERS (5-1 E to 5-35 E)
8th Edition : 2016-17 Pointers : Introduction, Declaration, Applications, Introduction to
9th Edition : 2017-18 Dynamic Memory Allocation (Malloc, Calloc, Realloc, Free), String and
String funictions, Use of Pointers in Self-Referential Structures, Notion
10th Edition : 2018- 19
of Linked List (No Implementation).
11th Edition : 2019-20 File Handling: File I/O Functions, Standard C Preprocessors, Defining
and Calling Macros and Command-Line Arguments.
Price: Rs, 150/-
onl SHORT QUESTIONS (SQ-1 E to SQ-26 E)
Printed at :Narula Printers,
Delhi.
SOLVED PAPERS (2017-18 TO 2022-23) (SP-1 E to SP-39 E)
& 2) Introduction to Components of a Computer System
1-2 E (Sem-1

Part-15 Programming Basics : 1-29E to 1-30E


Structure of C Program

1 Introduction to Part-l6: Writing and Executing


the First C Program
Syntax and Logical.
1-30E to 1-31E

Components ofA Part-17 :

Errors in Compilation
1-32E to 1-33E

UNIT Computer System part-l8 :


0bject and Executable Code 1-33E to 1-34E

Part-19 : Components of C Language 1-34E to 1-34E

Part-20 :
Standard I0 in C......... 1-34E to 1-35E

Part-21: Fundamental Data Types 1-35E to 1-37E


CONTENTS Part-22 :
Variables and Memory Locations 1-37E to 1-39E
.. 1-3E to 1-8E 1-39E to 1-41E
Part-1 : Introduction to Components of a Part-23 Storage Classes
Computer System: Memory

Part-2 : Processor 1-8E to 1-9E


Part-3 :
I/O Devices 1-9E to 1-10E
Part-4 : Storage 1-10E to 1-1E
: ..
Part-5 Operating System 1-11E to 1-13E

Part-6 : Concept of Assembler 1-13E to 1-14E

Part-7 : Compiler. 1-14E to 1-15E


Part-8 : Interpreter 1-15E to 1-15E
Part-9 :
Linker and Loader 1-15E to 1-18E
Part-10 : Idea of Algorithm and 1-18E to 1-20E
Representation of Algorithm
Part-11: Flowchart 1-20E to 1-25E
Part-12 : Pseudo code with Examples
1-25E to 1-26E
Part-13 : From Algorithms to Programs
1-26E to 1-28E
Part-14 : Source Code
1-28E to 1-29E
Programming for Problem Solving
1-3E (Sem-1
&2) 2) Introduction to Components of a Computer System
1-4 E (Sem-1 &
PART-1 Storage Unit
Introduction to Components of a
Computer System : Secondary
Memory Information
Storage
Program Output
Input (Results)
and Data Unit Unit
Primary
Questions-Answers Storage
Long Answer Type and Medium Answver
Type Questions
Control
Unit Indicates flow, of
Que 1.1. instructions and data
Explain the functional units of digital system
and their |Arithmetic
Indicates the control
interconnections. Logic Unit
exercised by the
OR control unit
What is digitl computer ? Draw block diagram N
Central Processing Unit (CPU)
of digital computer
and explain each components of it. Fig, 1.1.1. Functional unit of digital computer.
AKTU 2017-18(Sem-1), Marks 07 Arithmetic Logic Unit (ALU): :

1. ALU is responsible for carrying out following operations


OR Arithmeticoperations on data by adding, subtracting,
Draw block diagram of computer and explain each of its components a.
multiplying and dividing one set with another.
in brief. AKTU 2021-22(Sem-1), Marks 10 b Logicaloperations by using AND, OR, NOT and
exclusive-OR operation which is done by analyzing
Answer 8andevaluating data.
place where actual
Digital computer is an electronic computer in which the input is discrete
2
ALU of a computer system is the
execution of instructions takes place during processing
rather than continuous, consisting of combinations of numbers, letters and
Dther characters written in an appropriate programming language and operation.
epresented internally in binary notation. ii. Control Unit (CU): electronic control
This unit is mainly used for generating the operations.
main functional units/components of a digital computer are :
The
signals for the synchronization of various
. program execution such as
Central Processing Unit (CPU) : All the related functions for
2
memory read, memory write, I/O read, I/O write, execution
a. The CPUis the brain of a computer system. through the control signal
of instruction, are synchronized
b. This unit takes the data from the input devices and processes it generated by the control unit.
computer.
according to the set of instructions called program. manages and controls all the operations ofthe
3 It
C. The output ofprocessing of the data is directed to the output devices :
2 Input unit
for use in the outside world. following functions :
An input unit performs world.
d. CPU has two major parts calledALU and Control Unit. instructions and data from outside
It accepts (or reads) computer acceptable form.
instructions and data in
b. It converts these computer system
and data to
C. It supplies the converted instructions
for further processing.
Programming for Problem Solving 1-5 E (Sem-1 & 2)
2) Introduction to Components of a Computer System
:
1-6E (Sem-1 &
3. Output unit
An output unit performs following functions
:
computer
Que 1.3. What are the basic structural elements of
a
It accepts the results produced by a computer, which are in coded
system ?
form.
b. It converts these coded results to human acceptable (readable) Answer
computer system which
form. There are four : basic structural elements of
C. It supplies the converted results to outside world. are following
: :
4. Storage unit 1. Processor
computer and performs its data
It controls the operation of the
:
A storageunit holds (stores) a.

Data and instructions required for processing (received from input processing functions.
processor, it is often referred to as the
devices).
b When there is only one
b Intermediate results of processing. Central Processing Unit (CPU).
C. Results for output, before they are released to an output device. Main memory
:
2
a
Que 1.2. Draw the block diagram of computer system. Explain It stores data and programs.
computer is shutdown,
This memory is typically volatile i.e., when the
its different components with suitable example. b.
the contents of the memory
are lost.
AKTU 2018-19(Sem 2), Marks 07 memory are retained even when
C
In contrast, the contents of disk
OR
the computer system is shutdown.
Draw the architecture of digital computer system and explain its as real memory or primary
d Main memory is also referred to
all components. AKTU 2021:22(Sem-2), Marks 10
memory.
:
3 I/Omodules
Answver external
a
They move data between the computer and its
Components of computer system are: environment.
Hardware: Provides basic computing resources (CPU, memory, I/O a of devices, including
1
devices). bR The externalenvironment consists of variety
secondary memory devices (For example
: disks), communications
equipment, and terminals.
userl user2 user3 user4
bus
Compiler Assembler Text editor
...
Database
4.
Syides Communication among processors, main
memory, and
System I/Omodules.
Operating system
14. Draw the
Que mnemory
hierarchical structure of a computer
Computer hardware system, Explain each memory unit in brief.
AnswVer
Fig. 1.2,1.
The memory hierarchy system consists
of all storage devices employed
1. memory
2 Operating system:Controls and coordinates the use of the hardware a computer system from the slow but high capacity auxiliary
in memory, to as even smaller and faster cache
among the various application programs for the various users. to a relatively faster main
3 Application programs :Define the ways in which the system resources memory accessible to the high speed processing logic.
are used to solve the computing problems of the users (compilers, memory hierarchy:
2. Fig. 1.4.l shows the typical
database systems, video games, business programs).
4. Users : people, machines, other computers.
1-7E (Sem-1 &2)
for Problem
Solving Introduction to Components of a Computer System
Programming 1-8 E (Sem-1 & 2)
Storage
Access time (increasing)
(increasing) Answer
as a hierarchy to optimize
1 Memory system of a computer is organizedto
Registers achieve greater efficiency
the use of different types of memories and
Cache and economy.
Memory is organized in a hierarchy with thetop, highest performance and
Main memory
2.
expensive devices at the and with progressively
in general the most succeeding layers.
lower performance and less costly devices in
Secondary memory
Elements of memory hierarchy : Refer Q. 1.4, Page 1-6E, Unit-1.
Memory hierarchy.
Fig. 1.4.1.
these layers ; PART-2
Memory hierarchy is layered into Processor.
:
Registers
memory units which are used to handle the
1.
Registers are special computer and to speed
information between various units of the Questions-Answers
up the rate of information transfer.
on temporary basis.
b. These registers are used to hold information Long AnswerType andMedium Answer
Tyype Questions
:
2. Cache
Cache is used by the CPUfor
memory which is being accessed
over and over again. Que 1.6. Describe processor.
memory, it is put in
b Instead of pullingit every time from the main
cache for fast access. Answer
A processor is an integrated electronic circuit that performs the
3 Main memory: 1.
calculations that run a computer.
as
The main memory of the computer is also known RAM (Random and other basic
a
Access Memory).
2 Aprocessor performs arithmetical, logical input/outputs
instruction that are passed from an operating system.
b It is constructed from integrated circuits and needs to have electrical
power in order to maintain its information. 3. The CPUconsists of:
operations to
When power is lost, the informationis lost too. It can be directly CU which stores the instruction set, and specifies the
C.
accessed by the CPU: be performed by the computer.
or on the data
Secondary/Auxiliary memory : b ALUwhich performs arithmetical logical operations
4
received.
Secondary memory is computer memory that is non-volatile and by the CPU and the
persistent in nature and is not directly accessed by a computer/ 4 The CPUregisters store the data to be processed
procesSOr.
processed data also.
following hardware
b
It allows a user to store data that may be instantly and easily
5
Apart from CU and ALU, CPU seeks help from the
devices to process the data:
retrieved, transported and used by applications and services. connecting the CPU
C. The most common forms of secondarylauxiliary memory are flash Motherboard : It refers to a device used for components on the
memory, optical disks, magnetic disks and magnetic tape. with the input and output devices. The
computer and are kept
motherboard are connected to all parts ofa
components of a
Que 15 Why is memory system of a computer organized as a insulated from each other. Some of the
motherboard are:
hierarchy ? Discuss the basic elements of a memory hierarchy. and instructions
a, Buses :Electrical pathways that transfer data
among different parts of the computer.
1-9 E (Sem-1 & 2)
Problem Solving
Programming for synchronizingthe activities
a clock used for 1-10 E (Sem-1 & 2) Introduction to Components of a Computer System
System clock:It iscomputer.
b.
performed by the component that performs the We can also use a mouse to draw and paint
on the screen of the
Microprocessor : CPUactivities performed by the different computer system.
C.
processing and controls the
computer. memory of the 3. Scanmer :
parts of the and images
A scanner is an input device that converts documents system.
that contains the permanent cannot be modified
ROM : Chip information, which as the digitized images understandable by the computer
computer that stores can be produced as black and white images,
by the end user. memory b. The digitized images
to primary gray images, or coloured images.
Memory (RAM) It refers
:
ii. Random Access stores information and programs, until the by the CPU, is made available to the
-Output devices: The data, processedmnost
of a computer that as a chip that can be connected end user by the output devices. The commonly used output devices
computer is used. RAM is available
motherboard. are:
to the RAM slots in the between
Card:The videocardis interfaceown RAM
an
1. Monitor :
iii. Video CardISound Video cards also include their A monitor is the most commonly used
output device that produces
the monitor and the CPU. are
a.
microprocessors that used for speeding up the
processing visual displays generated by the computer.
and a sereen connected using cables, is
a
and display of graphic. b. The monitor, also known as on the expansion slot of the
is connected to the video card placed
a circuit board placed on the motherboard and of
A sound card
a computer. motherboard. The display device is used for visual presentation
used to enhance the sound capabilities of textual and graphical information.
:
PART-3 2. Printer on the screen, onto paper
The printer transfer the text displayed
user.
I/O Devices. sheets that can be used by the end
are dot matrix printers, inkjet
The various types of printer used
Questions Answers printers, and laser printers.
3. Speaker: converts an
Long Answer Type and Medium Answer Type Questions a. The speaker isan electromechanical transducer that
electrical signal into sound.
devices, to provide audio
They are attached to a computer output
as
b. audios.
as
output, such warning sounds andinternet
ue 1,7. Descrilbe VO devices.
4. Plotter: large documents,
a. a
The plotter is connected to computer to print
drawings.
Answer such as engineering or constructional
Input device: Input device can be connected to the computer system using pens or inkjets with colour cartridges for
b. Plotters use multiple link
cables. The most commonly used input devices are: printing. as
1. Keyboard : A standard keyboard includes alphanumeric keys, function Plotters are classified on the basis of their performance follows:
keys, modifier keys, cursor movement keys, spacebar, escape key,
numeric keypad, and some special keys, such as Page Up, Page Down, i Drum plotter
Home, Insert, Delete and End. Flat-bedplotter
2. Mouse
:
ii. Inkjet plotter
The mouse is also known as a pointing device because it helps to Vv. Electrostatic plotter
change the position of the pointer or cursor on the screen.
b. The mouse allows us to select elements on the screen, such as PART-4
tools, icons, and buttons, by pointing and clicking them. Storage.
1-11 E (Sem-1 &

Problem Solving 1-12 E (Sem-1 & 2) Introduction to Components of a Computer System


Programming for

Questions-AnsWers an
Que 1.9. What are the objectives and major functions of
Answer Type Questions operating system ?
Type and Medium OR
Long Answer types of functions
What is operating system ? Explain various
performed by an operating system.
? AKTU 2017-18(Sem-1), Marks 07
Que 1.8. What is storage device
OR
of computer system with neat ?and
Describe the basic componentsyou
Answer system which is employed to clean block diagram. What do mean by operating system
A storage unit is
a part of the computer
1. to be processed. |AKTU 2018-19(Sem-1), Marks 1O
store the information and instructions which Explain.
an integral part of the computer hardware
2 A storage device is process any computational work.
stores information/data to the result of
Answer
a computer would not be able to run
or even 1-5E, Unit-1.
3 Without a storage device, porting, or Components of computer system:Refer Q. 1.2, Page
up. storage device is hardware thatis used for storing,
A Operating system
:

boot
a manages the computer hardware.
extracting data files. 1. An operating system is software that
4. It can also store information/data both temporarily and
permanently.
An operating system acts as an intermediary between the user of a
2
Computer storage is of two types: computer and computer hardware.
ensure the
Primary storage devices
:
3. The hardware must provide appropriate mechanisms to programs
correct operation of the computer system and to prevent user
It is also known internal memory and main memory.
as
from interfering with the proper operation of the system.
1

2 This holds program instructions, input datá, and intermediate results. an enyironment in
It is generally smaller in size. 4. The purpose of an operating system is to provide manner.
which a user can execute programs in a convenient and efficient
3 RAM (Random Access Memory) and ROM (Read Only Memory) :
are examples of primary storage. Objectives of OS
use.
Secondary storage devices : 1. Convenience: An OS makes a computer more convenient to
1 Secondary storage is a memory that is stored external to the 2 Efficiency:An 0S allows the computer system resources to be used
computer. in an efficient manner.
as to
Ability to evolve An OS should be constructed in sucha way new
:
3.
2. It is mainly used for the permanent and long-term storage of permit the effective development, testing, and introduction of
programs and data.
system functions without interfering with service.
Hard Disk, CD, DVD, Pen/Flash drive, SSD, etc, are examples of
3

secondary storage. Functions of an operating system are :


1. Memory management :
a. Memory management refers to management of primary memory
PART-S or main memory.
memory
Operating System. b. An operating system does the following activities for
management :
Keeps tracks of primary memory, i.e., what part of it are in
Questions-Answers use by whom, what part are not in use.
process will get
In multi-programming, the OS decides which
Long Answer Type and Medium Answer memory when and how much.
Type uestions so.
i Allocates the menory when a process requests it to do
1-13
E
(SSem-1&2) 1-14 E (Sem-1 &&
2) Introduction to Components of a Computer System
Problem Solving
Programming for
process no longer needs it assembler and cross assembler.
Que l.10. Explain the concept
a of
memory when
iv. De-allocates the
or has been
terminated.
management: Answer
Processor OS decides which process
2 multi-programming environment, the time. This function is Assembler: a
a. In
processor when and for how
much
1. A program which translates an assembly language program into
gets the
machine language program is called an assembler.
called process
scheduling.
activities for procesSOr Assembler uses mnemonic symbols that
can be easily translated into
An operating system
does the following 2

b. machine codes.
management : program
processor and status of process. "The
:
Keeps tracks of controller. Cross assembler
as traffic assembler is an assembler that runs on a computer other than
responsible for this task is known process. 1 A cross

Allocates the processor (CPU)


to a that which it produces machine codes.
for
can be used for
processor when a process is no longer required 2. In such a situation, a faster and powerful computer
program development. The programs so developed are to be run
iii. De-allocates on
Device management: smaller computers. For such program development, cross assemnbler is
a
a
3 manages device communication via their
An operating system required.
following activities for device
respective drivers. It does the 3
as
These are further divided follows:
management : memory
task One-pass assembler:These are equipped to assign the
Keeps tracks of all devices. Program responsible for this
a.
addresses to the variables and translate the instruction
is known as the I/O controller. simultaneously in the first pass itself.
Decides which process gets the device when and for how Two-pass assembler : These read the program statements twice.
b.
much time. In the firstpass, it reads all the variables and assigns them memory
way. addresses. In the second pass it reads the instructions manipulating
üi Allocates the device in the efficient
iv. De-allocates devices. the variables and translates them to manipulate the memory
addresses.
4 File management : easy
a. A file system is normally organized into directories for
navigation and usage. These directories may contain files and PART-7
other directions. Compiler
An operating system do does the following activities for file
management :
i. Keeps track of information, location, uses, status etc. The uestions-AnsSWerS
collective facilities are often known as file system.
Decides who gets the resources. Long AnswerIype and Mediun Answer Type uestions
Allocates the resources.
iv. De-allocates the resources.
Que 1.11 Describe compiler.
PART-6
Concept of Assembler. Answer
1. A program which translates a high-level language into a machine
language is called a compiler.
2 A compiler checks all kinds of imits, ranges, errors ete. But its program
Questions-Answers
execution time is more, and occupies a larger part of the memory.
Long Answer Type and Medium Answer Type Questions
1-15] E(Sem-l
&2
Problem Solving Introduction to Components of a Computer System
Programming for 1-16 E (Sem-1 & 2)
memory utilization.
efficiency in
slow speed and low high-level language program once
It has the entire
compiler goes through program into machine codes. Questions-Answers
translates the entire
A

4
or twice and then
Type Questions
Long Answer Type and Medium Answer
PART-8
Interpreter. Deseribe about linker and loader.
Que 1.13.

Questions-Answers Answer
Linker: programs to form a
(combines) smaller
Answer Type.Questions Alinker is a program that links
Long Answer Type and Medium
1.
single program. or accumulating all the other program
2 Linking is a process of gathering are necessary program
for the
files and functions together, that
Describe interpreter. execution.
Que 1.12.
programmer uses the sqrt or pow function in the
3
For example, if the object code of this
OR
names of program, then the programmer have to link the
Describe compiler, interpreter, assembler. Write the function to the main function, which is included in the math.h library
compiler that are used in C programming. files. are frequently used. The
AKTU2017-18(Sem-2), Marks 07 4
While developing a program, subroutines
subroutines are stored in a library file.
The linker also links subroutines with the
main program. The linker
Answer 5

links mnachine code of the progTams.


Compiler : Refer Q. 1.11, Page 14E, Unit-l.
1

Therefore, it accepts user's program after editor has edited the program
Interpreter: 6 codes of the program.
1. An interpretêr isa program which translates statements ofa high-level and compiler has prodced machine
language program into machine codes. Loader:
2. It translates one statement of the program at a time. The loader is a program that loads machine
codes of a program into the
1
3
It reads one statement of a high-level language program translates ofit system memory.
into machine code and executes it. Then it reads the next statement exe is created, after linking the
the program again translatesof and executes it. In this way it proceeds
2
An executable file with extension
further till all the statements theprogram are translated and executed. executable object code.
program from the disk
Assembler :Refer Q.1.10, Page 1-14E, Unit-1. Now, after linking the process, loader loads
as
the process.
to the primary mnemory, which is known loading
Name of compiler used in C programming or relocatable format.
Interactive C 4. It accepts program either in absolute
5. If a program is in absolute format (i.e., the actual addresses of the
Lattice C loader simply
instructions and data are supplied by the programmer), the
GCC C loads the program into the systemn memory.
Micro Ccompiler specific addresses
6. Ifaprogram is in relocatable format, the locater assigns program into
Hippo-C to each instruction and data before the loader loads the
vi. Digital Mars memory.

Que 114. Discuss the various functionalities of compiler, linker


PART-9
and loader.
Linker and Loader.
1-17 E (Sem-1
&2)
Solving
Programming for Problem
Introduction to Components of a Computer System
1-18 E (Sem-1& 2)
Answer
of: of assembler. Explain compiler,
Various functionalities high level language
Que 1.16. Discuss the concept
1 Compiler:
program that converts
Compiler is a translator interpreter, loader and linker with example.
a. language. AKTU 2018-19(Sem-2), Marks 07
programs into machine source program and lists all the syntax
of
scans all the lines
Itb
OR
errors at a time. source and obio
produces a printed listing of the
The compiler
Write the short notes on
programs. i. Compiler
ong ii. Interpreter
2 Linker : a program compiled modules into iii. Linker
It is that links separately
|AKTU 2020-21(Sem-1), Marks 10
program.
standard C library with the iv. Loader
b It also combines the functions in the
code that we wrote. AnSWe
The output of the linker is
an executable program.
C. Unit-1.
Concept of assembler Refer Q. 1.10, Page 1-14E,
:
Loader : can be executed, it must be
Before a machine language program :
Compiler Refer Q. 1.11, Page 1-14E, Unit-1.
a.
stored in the memory of the computer. The
program itself may be
Unit-1.
stored in a disk. Interpreter : Refer Q. 1.12, Page 115E,
program called
b. This program is to be read into memory by another Loader and linker: Refer Q. 1.13, Page 1-16E, Unit-1.
a loader, which is already stored in the memory.
The loader is usually stored in a ROM and is automatically moved to
C. PART-1 0

the main memory by the hardware of the computer when it is


Idea of Algorithm and Representation of Algorithm.
switched on.
Que 1.15. Differentiate between linker andloader.
uestIONS AnswVers
Answer
S.No. Linker Loader Long Answer Type and Medium Answer Type Questions

1. Alinker isa program that links The loader is a program that loads
separately compiled modules machine codes of a program into Que 1.17. What do you mean by algorithm ? Explain the properties
into one program. the system memory.
of algorithm. What are the notations used to write an algorithm ?
2 Linker accepts users program| Loader accepts programns either in
after editor has edited the absolute or relocatable format. Answer
program and compiler has the steps to be
1
An algorithm is a set of instructions which describes
produced machine codes of the followed to get the solution of a problem.
program.
2
It can be finite step-by-step procedure to achieve a required result.
The output of the linker is an The output
ofthe loader is an object A. Propertiesof an algorithm :
executable program.
program.
4. Itis easier to develop, test and| It is difficult to test and debug
1, Finiteness Algorithm must complete after number of instructions
:

debug smaller programs. the have been executed.


longer programs. Absence of ambiguity : Each step must be clearly defined, having only
2
one interpretation.
1-19 E (Sem-1 &2)
Solving Introduction to Components of a Computer Systern
Programming for Problem 1-20 E (Sem-1 & 2)
a
must have unique defined
sequence : Each step are the main steps followed
Definition of
succeeding step. Que 1.19. What is algorithm ? What sum
preceding and
types of required inputs
and output must
in the development of
an algorithm Write an algorithm for
?
Input/output: Number and AKTU2017-18(Sem-2), Marks 07
4
be specified. instruction. of digits in a given number.
possible to perform each
Feasibility :It must be are : Answer
5.
to write an algorithn 1-18E, Unit-1.
B. The notations used specifies the problem to be solved Algorithm :Refer Q. 1.17, Page
of algorithm:
1 Name of the algorithm :It an instruction and it is an unsino) Steps followed in development
number:Identification tag of
problem.
Step
Step 1: Obtain a description the
of
2
positive integer. anddescribes the
Explanatory comment:It follows the step number
square brackets, Step 2 :Analyze the problem.
3 written within a pair of a high-level algorithm.
operation. It should be generally a Step 3:Develop
: It specifies the end of the algorithm. Itis
Termination adding more detail.
4 instruction in the algorithm. Step 4: Refine algorithm by
stop statement and the last
of an algorithm ? Write an
Step 5 : Review the algorithm. :
Que 1.18. What are the characteristics Algorithm for sum of digits
by 3 between
algorithm to find the sum of all the numbers divisible
N

Step 1: Input
11 and 50. Step 2: Sum= 0
Answer Step 3: While (N!=0),
Characteristics of algorithm are Rem = N%10,
1. Input and output These characteristics require that an algorithm + Rem;
or more zero or more inputs that are Sum =Sum
produces one outputs and have
externally supplied. N= NI10;
2. Definiteñess: Each operation must be perfectly clear and Step 4: Print Sum
unambiguous.
be effective,
Step 5 : Stöp
3. Effectiveness : This reguires that each operation should
paper a
Z.e., each stép can be done by a person using pencil and in finite
amount of time.
PART-11
44 Termination This characteristic requires that an algorithm must
: Flowchart.
terminate after a finite numbr of operations.
Algorithm : uestions-Answers
Step l : Initialize sum =0, a =11
Type Questions
Step 2: Repeat step 3, 4, 5, while (a = 50) Long AnswerType and Medium Answer
Step 3 :If(a% 3 == 0)
Step 4 : sum = sum +a advantages and
Que 1.20. What is flowchart ? Discuss
Step 5: Increment a to the factorial
disadvantages of flowchart. Draw flowchart find
a
Step 6: Print the sum of the given number.
Step 7:Stop
1-21 E
(Sem-1 &
Solving 1-22 E (Sem-1 & 2) Introduction to Components of a Computer System
Programming for Problem

Que 1.21. Write an algorithm and draw a flowchart to find the


Answer sum of digits of an integer number entered by the user.
Flowchart : the procedure for sole'
diagrammatic representation of AKTU 2018-19(Sem-2), Marks 07
1. A flowchart is
the problem. programmer uses for planning the
a pictorial representation that a Answer
Unit-1.
2. It is problem. provides an Algorithm : Refer Q. 1.19, Page 1-20E,
procedure for solution of checked, the flowchart Flowchart
:
thoroughly
3 Once developed and a program. Start
excellence guide for writing output
program will create the desired
A flowchart illustrates how the Read the number (n)
4. to calculate its sum
Advantages of flowchart: clearly shows of digits
representation ofalgorithm in the flowchart
1 The graphical
operates.
how control structure X= n/10
symbols are clearly indicated:
"START" and "STOP" tx* 10
2
3 Easy to understand.
: C=n-t
Disadvantages of flowchart Sum = Sum t+ C|

lead to confusion.
1. Complex flowcharts sometimes
programs.
2.
Connectivity issues in case of large :
n=x
Flowchart to find factorial of a given number
No
Stârt X=

Read
N/ Yes

M=l Display"The sum


F=1 is, sum
F=F* M|

Stop
No
M= M+1 KIs M= N? Pig. 121.1.

Yes
to find largest
Print F Que 1.22. Define flowchart and draw a flowchart
1), Marks 10|
AKTU2021-22(Sem
End among three numbers.
Fig. 120.1-1 Answer
1-20E, Unit-1.
Flowchart: Refer Q. 1.20, Page
1-23 E (Sem-1 &21
Problem Solving
Programming for Introduction to Components of a Computer System
1-24 E (Sem-1 & 2)
:
Flowchart Start Flowchart to find reverse of a number:
Start
Input A, B,C

Yes Declare n, reverse and


No of A > B remainder

No of A > C
No
ofB > C Read n
Yes
Yes Print C
Print A
Print B while No
Stop (n! = 0)
Fig. 1.22.1.
n=n/10
flowchart and Yes
Que 1.23. Describe the various symbols used in
reverse of a aber.
draw the flow chart to find the remainder=n%10;
AKTU 2021-22(Sem-2), Marks 10 reverse=reverse*10
+ remainder;
Answer
Symbols used in flowchart Print reverse
Symbol Symbol name Purpo8e
Stàrt/Stop Used at the beginning and end of End
the algorithm to show start and end Fig. 123.1.
of the program.
a reverse an
Process Indicates processes like Que 1.24. Write an algorithm and (draw flowchart to
mathematical operations. integer number entered by the user.
AKTU2018-19(Sem-2), Marks 07
Input/Output Used for denoting program inputs
and outputs. Answer
Algorithm :
Decision Stands for decision statements in a 1. Start.
program, where answer is usually,
2. Read the positive integer to be reversed.
Yes or No. 3. While the integer number being
reversed is greater than 10 do the
following steps :
Shows relationships between number to be reversed by using
Arrow a Extract the right most digit of the
different shapes. modulus function.
Construct the reversed integer by writing the extracted digit to
b. number.
On-page Connects two or more parts same
of
a
right hand side of the current reversed 10) to the RHS of the
Connector flowchart, which are on the 4 Write the integer (dividend which is less than
page. reversed number.
Solving 1-27 E (Sem-1
Programming for Problem &

Introduction to Components of a Computer System


1-28 E (Sem-1 & 2)
scanf("%d", &n);
ifn <= 1) clrscr();
1."); printf("Enter a number:");
printf("Enter a value greater than scanf("od", &s);
getch(); if(s < 0)
exit(0); printf(“Enter a positive integer value."):
else if(s == 0))
printf("Square root of 0 is 0");

tum
x=2; else
do

if(n%x = 0) n=1;
>=n *n &&&s< (n + 1) * (n + 1))
while(!(s
printf("%d\t",x);
n= x; n++;

else * n);
X++; d=s-(n
p= (double)d/(2 * n);
while (x <= n); d= (double)n
+ p;
getch();
root = (double)a -((p*p)/(2 *a);
printf(“\nSquare root of %d is %.3f,s,root);
Que 128.| Implement a C
program fromn the given algorithm.
I/To find the square root of anumber. getch();
1 Read a number, say s.

Ifs <0, s then go to step 16.f


Else if =
0
3
4 Print the value of sq as 0. PART- 14
Else Source Code.
6 Set n= 1.
7 While (!(s >=nn &&s (n + 1)*n1)) <

Do increment n by 1
9. End while
uestions-Answers
10. d=s- (n *n)
11. P= (double)d /(2*n) Long Answer Type and Medium
Answer Iype uestions
12, a= (double)n +p
13. root = (double) a - ((p *p)/(2* a));
14. Print the value of root
15. Endif Que l.29. What is source code ?
16. Exit
Answer generated
AnsweL code or assernbly code which is
#include<stdio.h>
1
Source code réfers to high level
by human/programmer.
int main() to read and modify.
liiiiiiliiiiiii 2 Source code is easy
programmer by using any High Level Language
or
int s, n; 3 It is written by human-readable.
double d, p, a, root; Intermediate language which is
Solving 1-29 E (Sem-l
Programming for Problem & 2)
Introduction to Components of a Computer System
comments that programmer puts for better 1-30 E (Sem-1 & 2)
4. Source code contains
understanding. char ch;
Source code is provided to
language translator which converts it into Z= sum(x, y); * function call */
code which is called machine code or object
5

machine understandable
code.
Computer cannot understand direct source code; computer understands
6. J* Definition of function sum() */
machine code and executes it. component of computer. int sum(int x1, int y1)
7. It is considered as fundamental
instructions/commands and statements whil.
Source code is a set of
8. computer programming languae
written by a programmer by usinga * return value of function
sum */
C, C++, Java, Python, Assembly language etc. return();
like as souree
statements written in any programming language termed
is
9 So,
code. PART-16
the
Writing undEcecuting ae,o First C Program.
PART- 15
Programming Basics : Structure of C
Program.
Qestions-AnSWers

Long Answer"ype
e
and Medium Answer Type Questions
an
Questions-Answers

Long Answer Type amd Medium Amswer


ype Questions
Que l.31. How to write and execute a C program?

Que 1.30.| Explain the structure of C program. Answer


C program statements
are written in lowercase letters. Uppercase letters
1
are used oñly for, symbolic constants.
Answer group program statements together and mark the beginning
Each program begins with preprocessôr directives that serve to provide Braces,
1. 2.
endoffunctions. A proper indentation of braces and statements
information about functions from standard libraries and definitions of and the debug.
necessary program constants. Examples of such directives are #include would make a program easier to read and
and #define. Following programshowshow the braces
are aligned and the statement
3.
2 Every C program consists of one or more functions, Function is a self is indented:
contained block of program which performs some kind of task. main ()
Every C program begins with main() function. Every function has a
return value. printf(hello C");
4
For example, consider the following program which gives summation of one line like :
x and y as z. 4. This program may be written in C")};
#include<stdio.h> /* Preprocessor Directive */ main () (printf("Hello
program more difficult to understand
int sum(int,int); /* function prototype for sum() */ However, this cycle makes the
int a, b, c; * Global Variables %/ and should not be used.
a program cannot be over
i float d; f* Global Variable 5 The generous use of comments inside comments not only increase the
int main() */. emphasized. Judiciously inserted programn logic. This is very
* main) function with return type */ readability but also help to understand the
testing the program.
int x, y; * Local variables to main() */ important for debugging and
int z;
1-31 E (Sem-1 &

Problem Solving Introduction to Components of a Computer System


Programming for 1-32 E (Sem-1 & 2)
program :
Executing a C Cinvolves a series of step. These:are:
program written in
a PART- 17|
Executing
Compilation.
Creating the
program; Syntax and Logical Errors in
1 program; are neededIfrom the Clibrary,
Compiling the
2 program with functions that Questiong-Answers
3 Linkingthe
and program.
Long Answer Type and Medium
Answer Type Questions
4
Executing the process of creating, compiling andlexecutinga
Fig. 1.31.1 illustratesthe
Cprogram.
occur during
logical error which
System ready
Que l.32.| Describe syntax and
compilation in C with example.
Program code Enter program Answer
Source program
Syntax errors
:
are
source we violate the rules of writing C syntax
Edit
program Errors that occur when error indicates something that
known as syntax errors. This compiler
can be compiled.
must be fixed before the code as compile
Compile source All these errors are detected by compiler and thus are known
C compiler program 2.
time errors.
Most frequent syntax
errors are:
Yes Missing Parenthesis ())
Syntax a.
ofvariable without declaring it.
errors ? b. Printing the value
C. Missing semicolon.
No Object code For exàmple
Link with IWC program to illustrate syntax errort.
System library system library #include<stdio.h>
a Executed object code void main)
Execute
int = 10;
x
Inpút data object code
int y = 15;
printf(“%d", (x, y)) // semicolón missed
Data error Logic and Logic error
data erTors ? Error:
error: expected before ' token
No errors Logical errors:
a program, desired output is not obtained
Correct output 1. On compilation and execution of provide
are given. These types oferrors which
when certain input values error are called logical errors.
Stop incorrect output but appear to be free
programmer
on logical thinking of the
Fig. 1.3LI Process 2. These errors solely depend the of execution and determine
of comnpiling and runing a C
program. easy to detect if we follow the line
and arèprogran takes that path of execution.
Why the
Programming for Problem Solving 1-33E
(Sem-1&
3
These are also known as runtime errors. a Computer System
For example: Introduction to Components of
1-34 E (Sem-1 &2) object code
I/Cprogram to illustrate logical error program is called the executable
The compiled and linked named a.out.
int main(0 3. automatically in another file
and is stored
int i = 0; PART- 19
Il logical error:a semicolon after loop
for (i = 0; i < 3; i++); Components of C Language.

printf("loop"); Questions-Answers
continue;
Questions
Medium Answer Type
getchar(); Long Answer Type and
return 0;
language
?
C

are the components


of

Que 1.34. What


PART- 18
Object and Executable Code. Answer comnponents of language:
C

Following are the to represent


or special symbol used
: Any alphabet, digit, in Care grouped
1.
Character setdenoted by a character. The characters
information is
Questions-Answers into four categories:
:A -Zor a -z
Long Answer Type and MediumAnswer a. Letters
Type Questions :0, 1----9 ">,.?7
b. Digits
symbols :-!@#
% ^ &
*(0_-+|\O0:; carriage return,
Special horizontal tab,
C.
spaces
:
blank space,
Que 1.33. Write White new line, and form feed.
a
short note on object code and d data types
executable code. desigmed to handle five primary secondary
language is several
Answer Data type
:C and void, and
2. integer, float, double union, and enumeration.
Object code: namely character, pointer, structure, It
data type like
array, does not change.
1 The source program constant is a fixed value entity that conputer and can be
instructions are translated into a Constants : A a location in the memory of the
for execution by the computer form that is suitable 3

2. The translation is done can be stored at memory address. during


after examining each instruction referenced through that vallue can change
correctness. for its variables is an entity whose of as symbolic
Variables : A thought can change.
3
If everything is alright, variable can be
the
translated program is stored on compilation proceeds silently
4.
program execution. A of the memory whose values
another file with the name and the representation of address assigned specific
4. This program 2
words which have been should not
is known as object a.0. Keywords:Keywords are those programs. Keywords
errors.
Executable code :
code.sCt etsiaqoo ) 5.
meaning in the
context of C language
avoid problems
or compile time
If any.mistakes in the syntax
1

as variable
names to
discovered, they are and semantics of the language are be used
listed out and the compilation
there. process ends right PART-20
2
The errors should be
corrected
the editor and the compilation in the source program with the help of Standard IlO in C.
is done again.
1-35E (Sem-1
Programming for Problem Solving a Conoputer System
Introduction to Components of
&

1-36 E (Sem-1 & 2)


Questions-Answers Questions-Answers
Long Answer Type andMedium Answer Type Questions Questions
Medium Answer Type
Long Answer Type and

C. Discuss primitive
data types in
Que 1.35. Describe the standard I/O function in C. data types in
Que l36. Define
specifier and range.
terms of memory size, format 2018-19(Sem-1), Marks 10|
Answer AKTU
1. C programming provides a set of built-in functions to read the given
OR examples.
input and feed it to the program as per requirement. types used in C with suitable
2 Cprogramming provides a set of built-in functions to output thedata on Discuss various data AKTU 2017-18(Sem-1), Marks
07
the computer screen as well as to save it in text or binary files.
Different I/O functions are: can
a variable
1. The getchar) and putchar() fünctions: Ansver
types are defined as the data storage format that
1 C data a specific operation.
a The int getchar(void) function reads the next available character store a data to perform program.
from the sereen and returns it as an integer. This function reads to use in a
define a vâriable before
only single character at a time. 2
Data types are used to
:
b
The int putchar(int c) function puts the passed character on the Primitive data types in Care
screen and returns the same character. This functiòn puts only are used to store whole numbers.
single character at a time, 1. Integer type :Integers
of integer type
on 16-bit machine:
2, The gets() and puts() functions : Size and range
The chargets(char *s) function reads aline Range Format
a. al from standard input Size (bytes) specifier
stream stdin into the buffer pointed to bysuntil either TVpe
or
a terminating
newline EOF (End of File). -32,768 to 32,767
The int puts(const char *s) function writes or signed int
the string s and a trailing int 0 to 65,535 ou
newline to standard output stream stdout. unsigned int 2
3. The scanf() and printf) functions :
short int
or
signed -128 to 127 ohd
The int scanf(const char *format, ...) function
the standard input stream stdinand scans reads the input from short int ohu
that input according to 1 O to 255
the format provided. unsigned short int
b. The int printf(const char *format, long int or signed -2,147,483,648 %ld
the standard output stream stdout ...) function writes the output to 4
to the format provided. and produces the output according long int to 2,147,483,647
4 0 to 4,294,967,295 olu
unsigned long int
PART-21 : Floating types are used to store real numbers.
Fundamental 2. Floating point type
Dta Types
Programming for Problem Solving 1-37 E (Sem-1
&)
a System
: Introduction to Components of Computer
Size and range of floating type on 16-bit machine 1-38 (Sem-1&2)
E

type
Type Size(bytes) Range Format A variable in C language must can
be given a type, which defines what
5. :
8, the variable will hold. It be
specifier of data
Can hold/store a character in it.
:
char
Float 4
3.4E–38 to 3.4E+38 %f int: Used to hold ana integer.
float: Used to hold float value.
double 1.7E-308 to 1.7E+308 %lf double :Used to hold a double value.
iv.
V. void a variable :
long double 10 3.4E– 4932 to 1.1E+4932 %Lf Declaring, Defining and Initializing
must be done before they are used
Declaration of variables
in the
1.
3. Character type: Character types are used to store characters value program. extern keyword, outside the main)
A variable is declared using the
Size and range of character type on 16-bit machine: 2
to
function.
has to now assign storage the
Defining a variable means the compilerprogram.
Type Size (bytes) Range Format 3 in the
specifier variable because it willwebe used provide the datatype and the variablea
To define a function must
4 multiple variables of same datatype in
char or signed char -128 to 127 name. We can even define
comma to separate them.
single line by using statement.
unsigned char 1 0 to 255 A variable can be initialized
and defined in a single
%c 5
Example:
4. Void type: Void type is usually used to specify the type of
#include<stdio.h>
functions I/Variable declaration (optional)
which returns nothing.
extern int a, b;
extern int c;
{
PART-22 int main ()
/* variable definition: */
Variables and Memory Locations.
int a, b; */
* actual initialization
Questions-Answers a=7;
b= 14;
using additionoperator */
Long Answer Type andMedium Answer Type Questions C=a+ b;
display theresult */
printf("Sum is:9%d \n", c);
Que 1.S7. What is variable ? How a variable return 0;
is declared, defined
and initialized?
Output:
Answer Sum is :21
you mean by scope of variable ?
Variable: Que 1.38.| What do
1. A variable is a name
given to a storage area that our programs
manipulate. can which a
Answer of theprogram in
2, Each variable in C language
has a : Scope determine the region we can use the
size and layout ofthe specific type, which Scope of variables program in which
variable's memory; the range of determines the i.e., the part of the
stored within that memory; values that can be defined object is visible,
and the set of operations object's name.
to the variable. that can be applied
3 The name of a variable can Types of variables: local to block in
which
underscore character. be composed of letters, scope of local variable is remains
It must begin with either a
digits, and the 1. Local variable:The ofthe local variable is till the control
4
letter or an underscore. variable is defined. The lifevariable is defined.
letters are distinct becauseC Upper the block in which
language is case-sensitive. and lowercase within
1-39 E (Sem-1
Programming for Problem Solving &

a Computer System
variablee Introduction to Components of
Global variable:The scope of global is global i.e.,,if avariable 1-40 E (Sem-1&2)
2 to functions that want to use
is declared outside, it is available all it. The : auto type-of-variable variable
list
as long as the program's execution Declaration
life of global variable remains :
For example
not come to end. . #include<stdio.h>
Static variable: The scope static variable is local to the bloolk
of
#include<conio.h>
of
which the variable is defined. The life of static variable i.e., value main()
different function calls.
variable persists between
auto inti=3;
{

Cum
PART-23 auto int i= 2;

Storage Classes. auto int i= 1;


printf("%d",i);

printf("%od", i);
Questions Answers
printf("%d", î);
Long Answer Typeand Mediumn Answer Type Questions getch();
)
Output : 123 :
Que 1.39. What is meant by storage classes of a variable ? Define 2. Register storage classregister :
Keyword
all types of storage classes with example: Default value
garbage
registers of CPU
AKTU 2017-18(Sem-1), Marks 07 Storage local toblock is
Scope ofvariable remains in that block where it
OR Life of variable till the control
defined
Brief the storage classes in with proper example.
C

register type-of-variable
variable list
AKTU2020-21 (Sem:1), Marks 10 Declaration
For example?
OR #include<stdio,h>
Explain in detail about all storage classes with proper example. #includekconio.h>
main()
AKTU 2021-22(Sem-1), Marks 10
OR register int k;<
Explain the different kind of storage classes in C programming. for (k=0;k 5; k+)
Hello");
print"\n
AKTU 2021-22(Sem-2), Marks 10 getch);

Answer Output
:

The storage class is associated witha variable which decides Hello


the default value of variable, where it would get stored, what would be Hello
of variable and what will be the scope of variable.
what will be the life Hello
There are four types of storage classes available Hello
1. Automatic storage class: (This is default in C: Hello :

Keyword class) 3. Static storage class static


:auto Keyword :
Default value Default value zerO
Storage
:garbage : memory
memory Storage local to block running, and it persist in
Scope of variable : local to block Scope variable : till program is
Life of
variabletill control remains in the block Life of variable various function calls
in whichit is
declaredi
1-41 E (Sem-1 &2)
Programming for Problem Solving

Declarations
:
static data type list ofvariable

2
: main( )
For example
int r( );
int r();
int r( );
Arithmetic Expressions
int r( );
UNIT and Precedence
static int count;
count++;
printf"\n%d", count);

Output:
CONTENTS
2
2-2E to 2-5E
3 as static hence value of this Arithmetic Expressions and
The variable count in function intr() is declared Part1 Precedence Operators and and
the execution ofprogram and when control reaches in
variable is retained
),
till
count value is available. But it is not available outside Expressions Using Numeric
function int r( Relational Operators
).
function int r(
: 2-5E to 2-6E
4 External storage class Part-2 Mixed Operands
Keyword :
extern 2-6E to 2-10E
Type Conversion
:
Default value zer0
Part-3
Storage memory 2-10E to 2-11E
Scope of variable global from point of declaration onwards Logical Operators
till program execution does not come to an end Part-4
Life of variable
.. 2-11E to 2-12E
For example : main( ) Part-5 Bit Operations
{ 2-12E to 2-13E
extern int i= 5: Assignment Operator...
Part-6
printf("od", i); *5*/ 2-13E to 2-1TE
increment( ): Part-7 Operator Precedence
der( ); Associativity
and
printf("%d", i); 2-18E to 2-27E
Conditional Branching Statements
Part Applying if and Switch
8
)
increment(
.. 2-27E to 2-30E
i++; Nesting if andElse and Switch
printf("%d", i); Part-9
6*/
)
der(
i- -;
printf("%d", i); P*5*/
When reference to the global variable occurs before
only it is required to put declaration of their declaration, then
in the block in which it is referred.
that variables using keyword extern
Ifglobal variable is declared before all 2)
functions then no need to redeclare 2-1 E (Sem-1 &
using extern. it Sl ioEEidua
Arithmetic Expressions and Precedence
2-2E (Sem-1 & 2)
2-3 E (Sem-1 & 2)
Programming for Problem Solving
PART- 1
Relational operator
:

are
sand Precedence: Operators and 2
Relational operators such greater
as than (>) or less than (<)
Arithmetic Expressions two variables and thus form
Expression using Vumeric and Relational Operators. used to compare values between
relational expressions. operators and their
ii Csupports six relational operators in all. These
meanings are shown in Table 2.1.2.
Questions-Answers Table 2.1.2. Relational operators
Operator Meaning
LongA Answer TVDe andMedium Answer 1VPe ueshons
less than
less than or equal to
t
<=
What greater than
Que 2.1.| Write a short note on operators inC language.
greater than or equal to
are the different types of operator ?

OR equal to
Explain different bitwise operators available in C with examples. p
not equal to
AKTU2017-18(Sem-2), Marks 07
:
3 Logical operator operators :
Answer i. Chas the following three logical
1, An operator is a symbol that tells the computer to perform certain Operator Meaning
mathematical and logical manipulations. logical AND
2
Operators are used in programs to manipulate data and variable. &&
An operator operates on variables and performs an action in a program. logical OR
It consists words or symbols.
of
logical NOT
Different types operators:of to test
&& and are used when we want
1.Arithmetic operators : The logical operators and make decisions.
An arithmetic operator is a symból which performs an arithmetic
1 more than ne condition
operation namely, addition, subtraction, etc. For example: a> b&& x10 two or more relational
The data on which such operations are carried out may be a variable kind, which combines
ii.
An expression of this logical-expression or a compound relational
or a constant.
expression, is termed
as a
iüi. Csupports the arithmetic operators as given in Table 2.1.1 expression.
Table 2.1.1. Arithmetic operators operator :
4 Assignment equal sign (=).
OperatorsSmbölFormR assignment operator is represented by the
Rorm Operation The
on the left side of= sign and it is assigned
The variable appearing
Multiplication x*y x times y on the right side of this sign.
the value appearing format:
Division xly x divided by y statement takes the following
The assignment
Remainder remainder ofx variable_name = expression;
divided by y oe
eÉ: is same ásx=x-y;
as x =x * y;
Addition
yis added to x 5 x*y: is same
x=
Subtraction
yis subtracted from x x/=y; is same as x/y;
Arithmetic Expressions and Precedene
2-4E (Sem-1 & 2) Programming for Problem Solving 2-5 E (Sem-1 & 2)
x=x % y;
x%
=
y;is same as
operator :
5.
Increment and decrement
decrement operators in
C
are represented h.
Que 2.2. Explain logical, unary and bitwise operators in detail.
The increment and 10
i.
++ and-- sign
respectively. --means“subtract 1» |AKTU 2021-22(Sem-1), Marks
++ means "add 1", and the operator
The operator operator pair "?; "is available i
ii. ternary
Conditional operator expressions
:A
of the form: Answer
to construct conditional Unit-2.
Logical operator: Refer Q. 2.1, Page 2-2E,
:
exp1? exp2: exp3
are expressions. Unary operator
expl, exp2, and exp3
a
where A unary operation is an operation
with only one operand, i.e., single
Bitwise operators
:
are used for 1.
7. operators are special operators which input.
which use two operands.
i. Bitwise level. This is in contrast to binary operations,
where A is a set. The function
f

manipulation of dataat bit them right An example is any function f: A,


testing the bits, or shifting
A
These operators are used for
3
to float or double.
is a unary operation
on A.
may not be applied
or left. Bitwise operators operators Bitwise operator: Refer Q. 2.1, Page 2-2E, Unit-2.
Table 2.1.3. Bitwise
Meaning PART-2|
Operator
bitwise AND Mixed Operands.
&
bitwise OR
bitwise exclusiye OR Questions-Answers
Questions
shift left Medium Answer Type
<< Long Answer Type and
shift right
>>
For example :, Que 2.3. Describe mixed mode operation.
#include<stdio.h>
main () Answer type are called
elements of real and integer
1. Expression that involve
unsigned int x, y; mixed mode expressions. floating point elements is
an expression containing both integer and
x= 128, y= 32; 2. If will be of type float. know
evaluated then the result identifier, then we should
X=X>> l; is to be assigned to some
x = % dln, x); 3. If this value identifier. assigned is float,
printf("After right-shifting by 1, the data type ofthean and the resulting value to be
If the identifier is int truncated.
y=y <<2; 4. fractional value must be mixed mode expressions are
=% then the floats -,
printf (After left-shifting by 2, y d\n", y); are used in forming operator (ie., +, $,/0).
5 The operators that operators, and the modulus
basic arithmetic
:
program segment
example: Consider the following
Output :
For int a = 4, b =2;
After right-shifting by 1, x= 64 float
x =
2, y
3;lunt
=

After left-shifting by 2, y = 128 a= (xly) + alb;


= 0.6+2 = 2.6
8 Special operators:C supports some special operators ofinterest such expression, we have + = (2.0/3.0) + 4/2;
as comma operator, sizeof operator, pointer operators (& and ) and In the a= (xy) alb
member selection operators (. and->).
Arithmetic Expressions and Precedenee
2-6E (Sem-1 & 2)
so the fractional part is truncated. Programming for Problem Solving 2-7E (Sem-1 & 2)
But a is an integer quantity,
i.e., a = 2 1. Implicit type conversion :
a. Cpermits mixing of constants and variables of different types in an
the
Que 2.4. Define operator and operands. Discuss about expression.
C automatically converts any intermediate values to the proper
different type of operators used in programming.
b

type so that the expression can be evaluated without losing any


IAKTU 2021-22(Sem-2), Marks 10 significance.
This automatic conversion is known as implicit type conversion.
2 Explicit type conversion: are
Answer a. C performs type conversion automatically. However, there
2-2E, Unit-2. a way that is
Operators and its types: Refer Q. 2.1, Page instances when we want to force a type conversion in
different from the automatic conversion.
Operands: to males in a
on an operator acts or works, b Consider an example, calculation of ratio of females
1. Operands are expressions or values which town.
2
Constants, variables, and function return values may all serve as ratio = female_number/male_number are
foriming expressions. declared as integers
operands and may be intermixed when Since female _number and male_number
more expressions. the program, the decimal part of the result of the division would
3
Operands may be complex in
be lost and ratio would represent
a wrong figure.
may also serve as an operand. converting locally one of the variables
4. The value returned by a non-void function This problem can be solved by
d

to the floating point as shown:


ratio = (float)
female_number/male number
PART-3 as explicit conversion
The process of sucha local conversion is known
Type Conversion. e.
or casting a value.
necessary because it convert different data
Necessity : Type conversion is
Questiong-Answers types into same type.
conversion and type
Que 2.6.| Write the
difference between type
?
Type Questions escape sequence characters
Long Answer Type andMedium Angwer casting. What are the
Answer conversion and type casting
:

Que 2.5. Explain type conversions. Difference between type Type casting
07 S.No. Type conversion process by
AKTU 2018-19(Sem-2), Marks casting is the
process of Type one type of data is
Type conversion is a
OR which
of different
1.
converting operators converted into another
? Why is necessary ? Explain common data forcibly
What is meant by type conversion data type into
a
about implicit and explicit type conversion with examples. type.
type. some cases, the conversion
AKTU 2017-18(Sem-2), Marks 07 only automatic In type to another
takes
2 In general, convert from one
Conversions are those that
automatically.
operand into a
place
Answer a "narrower"
one without losing
a process of convertingoperators of "wider"
Type conversion :Type conversion is
different data type into a common data type. Ifwe use two or more ifferent information. unary cast operators.
It uses
types of data items together in an expression, the C language compiler It is done by
two approaches:
automatically carries out the conversion of data types whenever needed.
3
Implicit
i
Explicit
and Precedence Programming for Problem Solving 2-9 E (Sem-1 & 2)
Arithmetic Expressions
2-8E (Sem-1 & 2)
: Que 2.8. Differentiate between type conversion and typecasting.
sequences character two single quotes. leftmost
Escape constant enclosed between character. The backslash is Write a program to input a floating-point number and find
1. It is a character before the digit of integral part of a number.
We can also
use a backslash (\)
2. escape character. |AKTU 2021-22(Sem-1), Marks 10|
known as the represent does not ho.
when the character that we want to
3. It is used associated with it.
any graphic not the normal character Answer
states that what follows is Unit-2.
4. The escape character Difference : Refer Q. 2.6, Page 2-7E,
but something else. character constants Program :
Table 2.6.1:Backslash #include<stdio.h>
Meaning
Constant main()
audible alert (bell)
\a'
backspace
float num;
form feed int ip, rm;
\f number");
new line printf("Enter a floating point
\n'
carriage return scanf(“%f, &num);
\r
horizontal tab
\t
vertical tab ip = (int)num;
\v
single quote rm =ip%10;
part=%dn",rm);
question mark printf("Left most digit ofintegral
backslash
null
return 0;

\0
operands in an arithmetic type conversion and type casting
Que 2.7.Define the term mixed program Que 2.9. Ilustrate the concept of
examples. Write in C to elaborate the AKTU 2021-22(Sem-2), Marks
10
expression with few
|AKTU2018-19(Sem-2), Marks
07
with program.
use of type casting.
BAnswer Unit-2.
: Q. 2.5, Page 2-6E,
Answer Type conversion Refer Page 2-7E, Unit-2.
2
5E, Unit-2. Q. 2.6,
Mixed operand : Refer Q. 2.3, Page :
Type casting Refer :
Program : Program for type conversion
#include<stdio.h> #include<stdio.h>
int main(){ data type
main () /linitializing variable ofshort
short a = 10;
lldeclaring int variable
int a, b; int b;
Ilimplicit type casting
a=3; b= 2; b=a;
printf(“\n%f",(loat) a/b); printf("%d\n", a);

Output :
1.500000
Arithmetic Expressions and Precedence
2-10 (Sem-1& 2)
E

Programming for Problem Solving 2-11 E (Sem-1& 2)

printf("%d\n", b):
2. Logical OR (||) operator:
even when both or even one of
Program for type casting: i. This type of operator returns true are satisfied.
#include<stdio.h> the conditions that are under consideration
int main() In any other case, it is bound to return false. For instance, the p|
p g are true (non-zero).
q will return true when both or one of and
q are true.
float a = 1.2; error for this It also returns to be true whenp and
I/Compiler will throw an
Ilint b= a; For example:
+ 1; or Saturday"
int b= (int)a statement "It is a holiday, if it is Sunday
printf(Value is %f\n", a);
of a We can write the
printf("Value ofb is %d\n",b); programmatically as:
== Saturday)
return 0; if(today == Sunday || today

I/It is a holiday
PART-4
Logical AND(&&) operator:
Logical Operators. 3. returns, true when both the conditions that
1. This type of operator happen to be satisfied.
are under consideration p
For instance, the &&
Questions-Answers In any other case, it is bound to return false.
are (non-zero).
i.
q will return true when both-pand
q true
Long Answer Type and Medium Answer Type Questions For example
:

programmatically as +:
"He is a hándsome guy"
We can write the statement,
if (skill=C &&
experience >=2).

operators? Describe the types logical


of
What are logical
{
Que 2:10.
IIHe is a handsome guy
operators.
Answer PART-5
Logical operators: Refer Q 2.1, Page 2-2E, Unit2.
Bit Operations.
Types of logical operators in :
1 Logical NOT () operators
This type of operator returns true whenever the conditions that Ouestions-Answers
are under condition are not at all satisfied.
Answer Iype uestions
In any other case, it is bound to return false. For instance, the Ip Long Answer Iype and Medium
will return true ifp is false, meaning, when p= 0.
For example:
Deseribe the types of
We can write the statement "A student can enroll in my program, ifthey are are bitwise operators ?
not enrolled yet" programmatically as : Que2.1l.|What
if(lenrolled) bitwise operators.
Answer 2-2E, Unit-2.
: Refer Q. 2.1, Page
I/Enroll the student
Bitwise operators
2-12 E (Sem-1 & 2) Arithmetic Expressions and Precedence
Programming for Problem Solving
2-13 E (Sem-1 & 2)
Different types of bitwise operators:
1. Bitwise AND operator : Answer
i. Bitwise AND operator is denoted by the single ampersand sign (&). Assignment operators : Refer Q. 2.1, Page 2-2E, Unit-2.
Two integer operands are written on both sides of the (&) operator. Different types of assignment operators:
6_"; This operator is used to assign the value on the right to the variable
Ifthe corresponding bits of both the operands are 1, then the output
1,
iii on the left.
of thebitwise AND operation is 1; otherwise, the output would be 0.
:
For example
2. Bitwise OR operator :
a = 10;
i The bitwise OR operator is represented by a single vertical sign(|). 20;
ii Two integer operands are written on both sides of the () symbol. b=
ch='y;
iii. Ifthe bit value of any of the operand is 1, then the output would be
1, otherwise 0. 2. 6p": This operator is combination of+ and= operators.This operator
first adds the current value of the variable on left to the value on the
Bitwise exclusive OR operator
:

right and then assigns the result to the variable on the left.
Bitwise exclusive OR operator is denoted by (^) symbol.
:

For example
Two operands are written on both sides of the exclusive OR operator. (a t= b) can be written as (a =a+b)
output
Ifthe corresponding bit of any of the operand is then the
1
ii 0.
Ifinitially value stored in 'a' is 5. Then (a +=6) = 11.
would be 1, otherwise
3. 6: This operator is combination of and'= operators. This operator
4. Bitwise shift operators :
first subtracts the current value ofthe variable on left from the value on
Two types of bitwise shift operators exist in C programming. the right and then assigns the result to the variable on the left.
on the left-side
The bitwise shift operators will shift the bits either For example :
or right-side. Therefore, we can say that the bitwise shift operator (a=b) can be written as (a=ab)
is divided into two categories : If
initially value stored in a is 8. Then (a'= 6) =2.
a. Left-shift operator: It is an operator that shifts the number This operator is combination of"* and operators. This operator
ofbits to the left-side. 4.
*
' to the value on
first multiplies the current value of the variable on left
on
b Right-shift operator: It is an operator that shifts the number
Dthe right ad then assigns the result to the variable the left.
of bits to the right side.
For example :
(a *=b)} can be written as (a=a*b)
PART-6 Ifinitially value stored in 'a' is 5. Then (a *=6) =30.
</=": This operator is combination ofP and operators. This
operator
Assignment Operator. 5

current value of the variable on left by the value on the


first divides the on
right and then assigns the result to the variable the
left.
uestIOns-Answers
For example:
EongAnswerype and ledum Answer ype (a =b) can be written as (a= a/b)
uestions (a/= 2) =3.
Ifinitially value stored in 'a' is Then
6.

Bue 2.12. What are assignment PART-7


operators ? Describe the types o
assignment operators. AssOciativity.
Operator Precedence and
2-14 E (Sem-1 & 2) Arithmetic Expressions and Precedence
Programming for Problem Solving 2-15 E (Sem-1 & 2)
Table 2.13.1.
Questions-Answers
Description Operator Associativity
Long Answer Type and Medium Answer Type Questions
Function expression ( Left to right
Array expression Left to right
Structure operator -> Left to right
Que 2.13. Write a short note on operator precedence and Structure operator Left to right
associativity in C language.
Unary minus
OR Right to left
Explain various types of arithmeticoperators in Clanguage Increment/Decrement ++/ Right to left
with
help of example. When precedence of two operators in an arithmetic One's complement
expression is same, how associativity helps in identifying which Right to left
operator will be evaluated first. Illustrate it with the example Negation Right to left
?
Address of &
|AKTU 2018-19(Sem-1), Marks 10 Right to left
Value at address
OR Right to left
What do you mean by operands ? Discuss the operator Type cast (type)
precedence Right to left
and associativity of all the operators. A Size in bytes sizeof Right to left
AKTU 2020-21(Sem-1), Marks10 Multiplication
Left to right
Division
Answer Left to right
Modulus
Arithmetic operators: Refer Q:2.1, Page 2-2D, Left to right
Unit-2. Addition
Operands: Refer Q. 2.4, Page 2-6E, Unit-2. Left to right
Subtraction
1. C has a precedence ássociated Left to right
with it.
determine how an expression involving This
more
precedence is used to
Left shift
evaluated. than one operator << Left to right
Righttshift
There are distinct levels of Left to right
one of these levels. precedenceand an operator may Less than
The operators at belong to Left to right
evaluated first. the higher level of precedence are Less than or equal to
Greater Left to right
3
The operators of the same
right' or from right to precedence are evaluated than Left to right
left, depending on the level. either from left to
associativity property an
Greater than or egual to
of operator. This is known as Left to right
4 Table 2.13.1provides the Equal to
a complete list Left to right
and their rules of operators,
their precedence levels, Not equal to
of association. The groups Left to right
decreasing precedence. areisted in the
order of Bitwise AND
5. Consider the &
followingconditional Bitwise exclusive OR Left to right
if (x== 10+ 15 statement: Left to right
6
The precedence
&& y<10) Bitwise inclusive OR
than the logicalrules say that Left to right
operator (&&)the additionoperator Logical AND
Therefore,
the addition andthe relational has ahigherpriority && Left to right
to: of10 and 15 operators Logical OR
is executedfirst. (==and,).
if (x==25 Thisis equivalent Left to right
&&y< 10) Conditional
?: Right to left
Arithmetic Expressions and Precedence
(Sem-1 & 2)
2-16 E
Right to left
2-17 E
(Sem-1& 2)
Assignment *= %= Right to left Programming for Problem Solving
+= -= &= Right to left
scanf("l%d %d%d", &a, &b, &c);
Right to left :
((b <c) ?b:c):
big
=
(a> b) ? (a>c)? (a: c))
Right to left printf("% The largest number is :% d', big);
Right to left getch() ;
Comma

associativity.
What are the different types of operators in C
language Que 2.16| Differentiate operator precedence and
Que 2.14.
the associativity and use of logical AND and logical
down the difference between Write a program in C to elaborate the
and also write AKTU2018-19(Sem-2),Marks 07|
precedence of operators. OR operators in
C.

Answer NHSweri
: Q. 2.1, Page 2-2E, Unit-2 associativity : Refer Q. 2.14, Page
2-16E,
Different types of operators Refer Operator precedence and
Difference between associativity and precedence of operators:
Unit-2.
Associativity of Precedence of Program :
S. No.
operators 1operators #include <stdio.h>
1 Associativity decides which Precedence decides which operator int main()
operator to execute first to execute first when there is more
=
when there is more than one than one different operator with int m = 40, n 20;
operator with same priority. different priorities. int o = 20, p =30;
2 Associativity indicates in If more than one operator is if (m >n && n != 0),{
conditions are true. \n");
which order two operators involved in an expression then, C printf(“&& Operator Both
ofsame precedence language has predefined rule of
(priority) executes. priority of òperators. This rule of if (o >P |p20) is true. \n");
priority of operators is called Only one condition
printf(“|| Operator:
operator precedence.
{
0))
Que 2.15|Write a program to find out the greatest number out o if (!(m >n && m!: are true. \n");
printf(“!Operator Both conditions
three numbers. AKTU 2020-21(Sem-1), Marks
else : Both conditions
are true. \n
Answer printf(“! Operator }
as false\n");
#include<stdioh> "But, status is inverted
#includeKConio.h> :
Output conditions are true.
main( ) && Operator:Both
Only one condition is true.
I| Operator:
conditions are true.
int a, b, c, big; !Operator : Both
But, status is
inverted as false.
printf("enter three
numbers a, b, c"); Lsnoitih..
Arithmetic. Expressions and Precedence & 2)
2-19 E (Sem-1
(Sem-1 & 2) Programming for Problem Solving
2-18E
PART-8 statement. Give its syntax.
Que 2.18. Explain if-else
Branching: ApplyinE
ý and Switch Statements.
Conditional Answer simple if statement. The
The if-else
statement is an extension of the
:
Questions-Answers general form is
If(test expression)
ype Questios
andMedium Answer {

LongAnswer Type True-block statement (s)

statement. Give its


flowchart, else
Que 2.17./Describe if
False-block statement (s)
con dition
Answer a control statement that
testa particular then thot
1 If statement is evaluated condition comes out to be true, statement-x the true-block statement(s),
Whenever, the out. Otherwise, the given
set of expression is true, then otherwise, the
or the set ofactions are carried If the test following the if statement are executed;
action immediately
aree executed, executed, not
e

actions is ignored.
simple ifstatementis
a
: false-block statement(s) or false-block will be
2 The general form of case, either true-block
In either illustrated in Fig. 2,18.1.
if(test expression) 3. of the
both. This is transferred subsequently
cases, the control is
statement-block; 4 In both the
statement-x.
statement-x; or a group of statement. Entry
a single statement
3 The 'statement-block'may be will be executed;
is true, the statement-block False
4 If the test expression
statement-block will be skipped and the execution will test
otherwise the True expression
jump to the statement-x. statement-block and the
5. When the condition is true both the False-block
statement-x are executed in
sequence. This is illustrated in Fig. 2.17.1 True-block statement
Entry statement

statement-x
True
test expression.

Fig. 2.18.1.
statement-block disadvantages of
False are the
if-else-ifladder. What
statement-x Que 2.19.|Describe
if-else-if ladder.
Next statement
Prccedonnn Programming for Problem Solving 2-21 E (Sem-1 &&
2)
Expressions and
Arithmctic
2-20 E (Sem-1 & 2) case constant 1:
decisione statement sequence;
when mWtipath break;
Answer ofputting if's together case constant 2:
another wav
There is an statement associntod statement sequence;
are involved. the form:
in whichgeneral
decision is a chain ofif's
following break;
2. A multipath is an if It takes the
with each else .default:
1)
if (condition -1; statement sequence;
statement
(condition 2)
else if :

statement -2: For example


(condition 3) #include<stdio.h>
else if #include<conio.h>
statement -3:
(condition n) int main( )
else if
statement -n; int a = 2, b=5, x =3, N, Y;
printf("Enter the value of N: \n);

es
else
default-statement; scanf("%d", &N);
statement-x; ladder. switch(N)
as the if-else-if ladder), to
dowmwev
construction is known the top (ofthe associated with it case 1:
This are evaluated from
statement
3. The conditions condition is found, the statement-x(skipping the Y= (a *x+ b) ^ 2;
As sOon as
a true transterred to the printf("The value ofY = %d", );
the control is
executed and break;
containing
rest of the ladder). then the final else case 2:
the n condition becomes false, Y= (a *x A2)+ (b ^ 3);
When all
statement will be executed. printf("The value of =%d", Y);
Ý

the default if-else-if ladder:


of
disadvantages of zig-zag form
break;
Following are various goes on increasing, the level case 3:
program
As the number of conditions increasing. As a result, the whole Y=-a * x+b;
1
also goes on
ofif-else ladder printf("The value ofY = %d", Y);
creeps to the right. corresponding if and else. break;
esxercised to match the
Care needs to be pair of braces. case 4:
to match the corresponding
2
x;

to be exercised Y=a ^2+


Care needs increases as well printf(The value ofY= %d", Y);
zig-zag form ofif-else ladder
3.
4. When nested-ifincrease, program. brealk;
as it becomes difficult to understand the default:
statement with example. What is the printf"This is default");
Que 2.20. Explain switch
language ?
role of switch statement in C programming return 0;
getch();
Answer
which B. Role of switch statement :
A. Switch statement: statement, 1 It allowS us to choose a block of statements
among several alternatives.
Switch case statement is multiple branch selection ofinteger or to process keyword commands such
a
1.

againstalist 2 The switch statenment is often used


successively tests the value of an expression as menu selection.
statementis:
constant.
switch
statement//Structure
of
2 General form of switch
switch (expression)
Arithmetic Expressions and Precedence
2-22 E (Sem-1& 2) Programming for Problem Solving
on 2-23 E (Sem-1 & 2)
useful when the selection is based
3 The switch statenment is especially
a
or of simple expression. The value of this
printf("Grade 5\n");
the value of single variable or char, but not of type double
expression may be of type int return 0;

according to the
Que 2.21.| A certain grade of steel graded
: Oue 2.22. What is case control structure in C? What is the reason
following conditions greater than 50.
Hardness must be for using break statement at the end of each case in case control
Carbon content must be less than 0.7.
strength mnust be less than 5600. block ? AKTU 2018-19 (Sem-1), Marks 10|
ii. Tensile are as follows :

The grades conditions are met. Answer


Grade is 10 if all the three (ii) are met.
Grade is 9 if condition (i) and Case control structures in C are: There are following type of case
condition (ii) and (iii) are met. control structure:
Grade is 8if (iii) are met.
Grade is 7 if condition (i) and 1. If statement Refer Q. 2.17, Page 2-18E, Unit-2.
:
one condition is met.
Grade is 6 if only of are met. 2. If else statement: Refer Q. 2.18, Page 2-19E, Unit-2.
Grade is if none the conditions
5

Write a program, which will require the user to give valuese Use of break statement :The break statement is used to terminate loops
or to exit from a switch statement.
content and tensile strength of the steel und
hardness, carbon of the steel.
consideration and output the grade Que 2.23.| Explain the use of default
in switch statement. Write a
AKTU 2018-19 (Sem-1), Marks 10
program that takes two operañds, and one operator user
and perform the operation and prints the result by usingthe
from
switch
Answer statement. AKTU 2018-19(Sem-2)), Marks 07
>
#include<stdio. h
()
Answer
int main
Use of default inswitch statement : A switchstatement can have an
optional case,
default whichmust appear at the end of the switch The default
int hard,ts; case can be used
for performing a task when none of the cases is true. No
break needed in the default case.
is
float cc;
content of the Program:
printf("Enter the Hardness, Tensile strength and carbon #inchude Kstdio.h
steel \n");
#include <conio h>
scanf("%d%d%f", &hard, &ts, &cc);
void main()
if(hard>50&&cc<0.7&&ts>5600)
printf(" Grade 10\n"); int a, b, c;
else if(hard>50&&ce<0.7&&!(ts>5600) char ch;
printf("Grade 9\n"); clrscr);
else if(hard>50)&&ce<=0.7&&ts>5600) print("Enter operator(t,-,1, *, %)
\n");
printf("Grade 8\n"); scanf("%c", &ch);
else if(hard>50&&!(cc< 0.7)&&ts>5600) printf("Enter the values of a and b\n");
scanf("%d%d", &a, &b);
printf("Grade 7\n");
else if(hard>50| |cc<0.7| | ts>5600) switch(ch)
printf("Grade 6\n");
case '+':c=a+;
else
Arithmetic Expressions and Precedence
2-24 E (Sem-1 & 2) Programming for Problem Solving 2-25 E (Sem-1 &2)
is %d", c);
printf(“Addition of two numbers char ch;
int a, b, result;
break;
Il Asking for Input
case : c=a-b; %d", c); printf("Enter an Operator (+,, *, ):");
printf(“Subtraction of twonumbers is scanf("%c", &ch):
printf("Enter two operands: \n");
break; scanf("od %d", &a, &b);
case ; c=a * b; %d", c); switch(ch){
printf(Multiplication of two numbers is case 4:
result a+b;
break; break;
case
case V:c=a/b;
is %d", c);
printf(Remainder of two numbers result =a-b;
break;
break; case *.
case %: c=a% b; ,
%d", c);
result =a
numbers is break;
printf("Quotient of two case /:
break; result = a/b;
operator"); break;
default: printf("Invalid
break; printf("Result =%d, result);
return 0

getch();
Que 2.25. Compare if-elseif ladder and switch case. Write a menu
driven program to perform basic functions, of calculator.
Output:
,*, %) AKTU 2021-22(Sem-1), Marks 10|
Enter ooperator (t,
Answer
a
andb
Enter the values of Difference:

13
If Else-If Ladder Switch
4 to select among two The switch statement is used to
Addition of two numbers is a program to 1, It is used
switch case ? Write alternatives. select among multiple alternatives.
Que 2.24. What is use of breakin
case in character format. 2. It can have values based on
It values based on user choice.
develop a calculator using 2021-22(5Sem-2), Marks 10| constraints.
AKTU
3. It implements linear search. It implements binary search.
can be
4. Float, double, char, int and Only int and char data types
Answer out of the sw other data types can be used. used in switch block.
statement transfers the control cases as, they
Use of break: The break 5. It is difficult to edit the if-else It is easy to edit switch
statement. statement, if the nested if-are recognized easily.
Program: else statement is used.
#include <stdio.h
int main(O{
Arithmetic Expressions and Precedence
2-26 E (Sem-1 & 2) Programming for Problem Solving 2-27 E (Sem-1 & 2)
h>
Program : #include<stdio. scanf("%d", &numl);
void main() printf(“Enter the second Integer \n");
scanf(“%d", &num2);
=
0)
int num l,num2,0ption; if(num2
do
printf(“Error \n");
printf(“\nChoose your option \n";\n3.Multiplication\n4.
\n2.Subtraction
printf(“1.Addition else
Division \n5.Exit\n");
scanf("%d",&option); printf("The Division of %d and %d is : %d\a", num1, num2,
==5) num 1/num2);
if(option

break; break;
}
case 5:
switch(option) break;
default:
case 1: printf(“Invalid option \n");
printf(“Enter the first Integer \n"); break;
scanf("%d", &num1); \n");
)

print[("Enter the second Integer Jwhile(option != 5);


scanf("%d", &num2); num1,
printf("The Addition
of od
and %d is: %d\n",
num2, num1 +num2); PART-9
break; Nestingifand Else and Switch.
case 2:
printf("Enter the first Integer\n");
scanf("%d", &num l); Questions-Answers
printf("Enter the second Integer \n);
scanf("%d &num2); Long Answer Type and Mediumn Answer Type Questions
printf("The Subtraction of %d and %d is:
%d\n", numl, num2, numl -num2);
break; Que 2.26. What is nesting of if-else statement ? Give its flowchart.
case 3:
printf("Enter the first Integer \n");
Anson
scanf("%d", &num 1);
printf("Enter the second Integer \n";
1 When a series of decisions are involved, we may have to use more than
one if-else statement in nested form as shown in Fig. 2.26.1.
scanf("%d", &num2); 2
Ifthecondition-l is false, the statement-3 will be executed; otherwise it
printf("The Multiplication of %d and %d is: continues to perform the second test.
%d\n", numl, num2, num1 * num2); 3
If the condition-2 is true, the statement-l will be evaluated; otherwise
break; the statement-2 will be evaluated and then the control is transferred to
case 4: the statement-x.
printf("Enter the first Integer \n");
Precedenco
Arithmetic Expressions and Programming for Problem Solving 2-29 E (Sem-1 & 2)
2-28 E (Sem-1 & 2)
condition-1) Answer
-if (test
{
condition-2); Nested switch statements refers to switch statements inside of another
if (test switch statements.
statement-1: The syntax for a nested switch statement is as follows :
switch(ch1) (
case 'A':
else printf[("This A is part of outer switch" );
statement-2; switch(ch2) {

case 'A:
) printf("This A is part of inner switch" );
else break;
case 'B':* case code */
statement-3;
)
break;
statement-x;
case "B:/* case code */

Que 2.28.| Differentiate between nested-if and switch statements


Entry
in C with example.
test True Answer
False expression 1
? Difference between nested-if andswitch statements:

test True
SNo. Nested-if Switch statements
False expression 2 1 Nested-if checks every Switch statement checks the
? condition. condition first and jumps to the
suitable case statement.
statement-1 In nested-if execution time will A-switch statement
is more
statement-3 statement-2. be more and code becomes structured. Hence, execution
lengthy. time is less.
3
The syntax of nested-if is as The syntax of switch statement
follows :

is as folows :
if(condition 1) switch (expression)
statement-x
if (condition 2)

statement 1;
Hlsll
case value 1:
statement:
statement ;
Next statement
break;
toment. else
Fig. 2.26.1. Flow chart of nested if-else statemen
default :
statement 2;
}
statement;
Que 2.27.|What is nested
statement ;

switch ?
Precedence
Arithmetic Expressions and
2-30 E (Sem-1 & 2)
statements used inc

3
different type of control
Que 2.29. Explain AKTU
2020-21(Sem-1), Marks 10
programming with example.

Answer programming: NIT


Different type
of control
statements used inC
2.17, Page 2-18E,
Unit-2. Iteration and Loops
Q.
statements : Refer Page 2-19E, Unit-2.
If statements : Refer Q.
2.18, Unit-2,
If-else 2.26, Page 2-27E,
if-else statement : Refer Q. 2-19E, Unit 2.
Nested 2.19, Page
If-else-if
statements : Refer Q.
CONTENTS
... 3-2E to 33E
.....
uan
Part-1 Iterationand Loops : Use
of While
Part2: D0-while and For Loops
33E to 3-13E
Part-3 : Multiple Loops
Variables ...... 3-13E to 3-14E

serie Part-4:
Part-5 :Goto

Part-6:

Part7
Part-8
Use of

and
Break.....
and Continue Statements

Arrays: Array Notation.....


Representation
Manipulating Array Elements

Using MultiDimensional
...3-23E
Arrays....
..
3-14E to 3-16E

3-16E to 3-17E
.3-1TE to 3-23E

3
to 3-23E
23E to 3-24E
Part-9 Character Array and Strings .... 3-24E to 3-25E
Part-10: Structure.. 3-25E to 3
32E
Part-11: Union.......... 3-32E to 3
34E
Part-l2: Enumerated Data Types..... 334E to 3-36E
Part l3: Array of
Structures.. 3
36E to 3-37E
Part14 Passing Arrays to Functions.o S7E to 3
39E

3-1 E (Sem-1 & 2)


Progranmming for Problem Solving 3-3 E (Sem-1 & 2)
Iteration and Loops
& 2)
3-2 E (Sem-1 Evaluate the
expression logexp
1
PART-
of While.
Use
Iteration and Loops:
false
condition
Questions-Answers ?
Questions true
Answer Type
Type and Medium
Long Answer Body of while Statement outside
while

Fig. 3.2.1.]

Que 3.1. What is loop ?


of+h PART-2
one is called the bodv
Answer program consists of twO parts, Do-Whileand For Loops.
statement.
1 A loop in a called the control eithertm
loop and the other is whose result is
statement performs a logical test
The control Questions-Answers
2
or false. statements contained in
the logical test is true, then the loop is terminated
3 Ifthe result of are executed. Otherwise, the statements Long Answer Type and Medium Answer Type Questions
loop
the body of the control
Cprovides the following
three types of loop
4.

statement
a While Que 3.3. Describe do-while statements.
Do-while statement
b
C.
For statement Answer
while statements. This is usedto execute a set ofstatements repeatedly, until the logical
Que 3.2. Describe the post-test loop, because, the test for
testresult infalse. This is called
repetition is made at the end of each pass.

Answer statements repeatedly, as ii The syntax of do-while is as follows?


While statement is used
to execute a set of
1
condition is true. do
long as the specified :
loop is as follows
2 The syntax of a while
statement;
while (logexp)

statement; while (logexp);


iii The flowchart of do-while statement:

3. The flowchart of while statement:


Iteration and Loops Programming for Problem Solving 3-5E (Sem-1 & 2)
34E (Sem-1 & 2)
clrscr ();
Execute the body
printf(“\nEnter the value of n:");
of scanf("%d", &n);
do-while for (i = 1.0; i < n;i ++)
{

a
=i/i+ 1);
Evaluate logical
expression Sum = Sum+ a:

printf(\n The sum of


series 1/2 + 2/3 + ...... +%d/%d is
n, n + 1, sum);
%f.
is False
True getch ( );
result

Que 3.6.| Write a program to check


Next statement the number is palindrome or
not. The program should accept any
arbitrary number typed by
Fig. 3.3.1.] user. AKTU 2017-18(Sem-1),
Marks 07
OR
Write a program to find the entered
Que 3.4. Describe for statement. number is palindrome or not.
AKTU 2020-21(Sem-1), Marks 1o
Answer programmer knows how many times
a Hnswer
i for statement is used when the #include<stdio.h>
are to be executed.
set of statements int main()
a
The syntax of for
statement is as follows.:
expression3;)
for (expressionl; expression2; int n reverse 0,
t;
printf(“Enter a
number :\n");
statemènt; scanf("%od", &n);
t=n;
while (t != 0)
Write a program to add first
C seven terms of the
Que 3.5. .......
+ + reverse =reverse * 10:
following series using for loop. 1/1!+ 2/2! 3/3!
reverse = reverse + t%10;
AKTU 2017-18(Sem 1), Marks 07|
t=t/10;
Answer if (n = reverse)
#include<stdio.h> printf("%d is a palindrome number.\n", n);
#include<conio.h> else
void main () printf(“%od is not a palindrome number.\n", n);
return 0;
}

int n;
float sum =0.0, a, i;
Programming for Problem Solving 3-7 E (Sem-1 & 2)
Iteration and Loops
Sum
=
sum + (r* r * r) :)
3-6E (Sem-1 & 2) number == nun)|
is prime if(sum
program to check the number number is : % d", num);
Que 3.7. Write a 2017-18(Sem-1), Marks 0Z printf(“Armstrong
IAKTU
or not. return 0:

Answer
#include<stdio.h>
Que 3.9.Write a program to generate a following numbers

Um
{
main() structure :
= 0;
int n, i, count 12345
printf(Enter any number n:"); 1234
scanf("%od", &n); 123
<= n; i++){
for (i = l; i 12 AKTU 2017-18(Sem 2), Marks 07
{
0)
if (n % i==
Answer
COunt ++;
#include<stdio.h>
#include<conio.h>

Ies
== 2) { int main( ){

if (count int i, j, rows ;


printf(n is a Prime number"); printf("enter number ofrows :");
scanf("%d", & rows)

else
for(i ÷rows; i 1i) s
number");
printf("n is not a Prime forj =1;js-, ++)
printf("%d",);
return 0;

Armstrong number from printf("\n,


Que 3.8. Write a program to fünd the
07 return0;
AKTU 2017-18(Sem-2), Marks
1 to 100.
Que 3.10. Write a program in C
to print following pattern with
Answer appropriate comments:
#include<stdio.h> 10
int main{
; 765
int num, r, sum, temp 43211
for (num=1; num < 100;
num ++) AKTU 2018-19(Sem-2), Marks 07|
temp = num;
sum 0;
=
#include<stdio.h>
while (temp != 0) #include<conio.h>
r=temp%10 ;
temp temp/10;
=
Iteration and Loops 3-9E (Sem-1 & 2)
Programming for Problem Solving
(Sem-1 & 2)
3-8E
void main( ) return 0:

int i, j, k= 10;
clrscr( ); <
for (i = 1; i 5;
i++) Que 3.12.] Write a program two find out the odd andeven number
++) from the array elements and its count.
for (j = 1;j<= ;j AKTU 2020-21(Sem-1), Marks 07|
printf("%d", k);
Answer
#include<stdio.h>
printf"ln");
int main()
getch( );
pattern :
program to print for the int Size, i, a[10];
Que 3.11.
Write a int Even_Count = 0, Odd_Count = 0;
printf("\n Please Enter the Size of an Array : ";
scanf("od", &Size):

series
Marks 07
AKTU2020:21(Sem-1), printf("\nPlease Enter the Arfay Elements\n");
for(i = 0; i< Size; i++)

Answer scanf("%d", &alil);


#include<stdio.h>
int main0
for(i0; i<Size;i++)
=
int n, m 1; of rows");
printf("Enter the number ilali)
scanf("%d",&n) %20)
for(int i = n; i >= 1; i
Even Count ++;
}

for(intj = 1;j <= i;j++)


else
{
{
i==n)
iflj==1 || j==i || Odd_Count++;
printf(*");
else
printf ");

printf("\n);
Iteration and Loops 3-11 E (Sem-1 & 2)
» Programming for Problem Solving
3-10 E (Sem-1&
2) Array = hd
Even Numbers in this int main(){
Number of Cosma transpose (10] [101;
printf(“\n Total Array =%d",
Odd int m, n, i, j, matrix(10] [10],
Even_Count); Numbers in this printf("Enter rows and columns :\n"):
Number of Odd
printf("\n Total scanf("%od%d", &m, &n);
return 0; printf("Enter elements of the matrix\n");
s
of series using function for (i = 0; i < m; i++)
a program to find
the sum for (j = 0; j < n; j++)
Que 3.13. Write Marks i
AKTU 2021-22Sem-1), scanf("%d", &matrix[iJ lil):
.......se..n terms. for (i = 0; i< m; i++)
1!+ 2! + 3! +4!+
for (j = 0; j < n; j++)
transpose lj]li] = matrixi] j1;
Answer
#include<stdio.h> printf("Transpose ofthe matrix:\n")};
int main() for (i = 0; i< n; i++){
llvariables for (j = 0; j<m; j++)
sum = 0;
num, i,j, fact, of series: \n");
int printf(“%d\t", transpose[il (j1);
printf("Enter the last numberIMast number
of series

scanf("%d",&num);
printf(“\n);
N/Noopfor finding factorial and
sum
}
num; i++)
for(i = 1;i<=
return 0:

fact = 1;

ifi!= num) Que 3.15. program to print the pattern


Write.a
printf("%d!+", i);
else 12
123
printf("%d !=", i);
1234
forj = 1;j<=i; j++), 123

fact = fact *i: 12


AKTU 2021-22(Sem 2), Marks 10
sum sum + fact:
= 1

Answer
printf("%d", sum); #include <stdio.h>
return 0; int main)

transpose of matrix
int i, j, N;
Que 3.14. Writea program to find Marb printf("Fnter N:");
2021-22(Sem-1),
AKTU scanf("%d", &N);
I/ Prints upper part of the pattern
= 1;
Answer for(i i<=N; it+)
include <stdio.h>
lnch

Iteration and Loops


3-12 E (Sem-1&
2)
Programming for Problem Solving 3-13 E (Sem-1 &2)

for(j = 1;j<= ;jt+) for(int j = 0;j < i; j++)

printf("%d", j); printf“);

printf("\n"); for(int k= 1; k<n-i; k++)


{

part of the pattern printf(“);


I/ Print lower
for(i N-1; i>= 1; i-))
=

printf("\n");
j++)
for(j = 1;j<=
i;
for(int i = 1; i<n; i++)

printf("%d", j); for(int j = 1;j<n-i; j++)

printf("\n"); printfr“ ");

for(int k= 1; k<=i+1; k++)


return 0;
printf(“*");

a program for pattern


Que 3.16. Write printf(“\n");

kk
return 0;

PART-3
Multiple LoopsVariables.
**

Marks10|
&****
SAKTU 2021-22(Sem-2), uestions Answers
Long Angwer Type and Medium Answer Type Questions
Answer
#include <stdio.h
int main(void)
{
Que3:17. Write a short note on: multiple loops variables.
int n; Angwer
printf("Enter the number of columns");
C's for statement is more flexible because each of the expressions can
1

scanf("%d", &en); comprise multiple statements, which in turn allow multiple loop variables
lIprinting the upper part of the pattern. that can be of any type.
for(int i= 0;i<n; i++)
SCALE
Inch

Iteration and Loops Programming for Problem Solving 3-15 E (Sem-1 & 2)
3-14 E (Sem-1 & 2) a
a single expression of for 3
A break used in a switch statement will affect only that switch.
statements are used In a loop statement when break is encountered, the loop is immediately
When multiple commas. no 4
statement, they are separated
by multiple statement is terminated, and program control resumes at the next statement following
have values, and this form of
3. All C statements last component
the loop.
exception. suchamultiplestatement is the value the
of
:
of
For example
4. The value statement :
#include<stdio.h>
5. Consider the following for = 1.0;
= 0, count2 #include<conio.h>
for (countl && count2 <= 100.0;
count1 <= 10 + count2, count2 *= 2.5); int main
sum = ++count1 description of this is
operational semantics
6. The
count1=0 int a;
count2= 1.0 for(a = 0; a < 100; a++)
{
loop: goto out
>
if count1 > 10
100.0 goto out
printf("%d", a);
if count2 if(a == 10)
countl
=
countl+1
sum = count1 + count2 break;
count2= count2 * 2.5
getch();
goto loop havo
does not return 0;
out:.. C for statement does not need and thus }

7 The example : 012345678910


itselt Output
loop body. happen to be part of
the for statement
All the desired actions a. The above program prints the number 0 to 10 on the screen.
Then the loop terminates because break causes immediate exit
rather than in its body.
expressions are multiple
statementS
resulting
b
from the loop, overriding the conditional test a 100.
9 The first and third expression is evaluated, but the
cases, the whole
10. In both of these
value is not used in the
loop control.
Que 3.19. What is
the use of break statement in loops ? Write a
program in C using while loop to elaborate
the use of break
PART-4 statement. |AKTU 2018-19(Sem-2), Marks 07
Use of Break.
Answer

Questions-AnSwers
A. Use of
break statement:Refer Q
3.18, Page 3-14E, Unit-3.
B. Program
#include <stdio.h>
Answer IypeQuestions int main (){
Long Answer Type and Medium /* local yariable definition */
int a = 10;
* while loop execution */
purpose of the break statements ? Wtn while( a< 20){
Que 3.18.| What is the included? printf(value of a: %d\n", a);
which control can break statement be
statements the a++;
if( a> 15) {
Switch /* terminate the loop using break statement */
Answer a
or to exit from break; ) )
statemenk
The break statement is used to terminate loops or sswitch return 0;
while, do-while
statement. It can be used within for,
The general form of the break statement is
:
2.
break;
Iteration andLoops Programming for Problem Solving 3-17 E (Semn-1 &2)
3-16 E (Sem-1 & 2) 4 For example,
for (i = 1; i <= 2; it+)
:
Output
value of a: 10 for (j = 1; j <= 2; j++)
value ofa: 11
value of a: 12 if(i ==j)
value of a: 13 continue;
value ofa: 14 printf("\n%d %d", i,j)
value of a: 15
PART-5
Statenents. Output
Goto and Continue 12
21
Questions-Answers Oue 3.21. What is the difference between
Questions break and continue
Mediumn Answer 1ype statement in C? Describe the structure of switch-case
Type and with neat
Long Answer example.
Gi Answer
statement 2
purpose of continue Difference between break and continue statement
Que 3.20. What is the inC:
flowchart. s.No. Break statement
example and its Continue statement
loop totol
1
A break statement allows us to The continue statement
is used
Answer next iteration ofthe terminate the execution of loop| for the next iteration of the
statement is used for theHlence, is used to terminate the loop
The continue it and to jump out of th loop. to take place skipping any code
1. any code in between. next iteration of the loop.
place, skipping continue with the in between.
current iteration and conditional test
causes the updation and then the program The, géneral format of break The general format of continue
2
For the loop, continueexecute. For the while and do-while loop, statement is statementis:
portions of the loop to break;
conditional tests. Continue:
control passes to the shown in Fig. 3:20.1,
flowchart of the continue statement is 3.The break statement can alsoContinue statement is not used
3
The be used with
switch cáse with switch statement.
Start of loop structure.

Structure of switch case: Refer Q2.20, Page 2-20E, Unit-2.

Test PART-6
condition true Continue
Arrays : Array Notation,and Representation.
within the
loop

I false uestionsAnswers
Rest part of ong Answer Type and Medium Answer Type uestons
the loop

Ntotement Sua
Fir. 3.20.1. Flowchart of continue
Programming for Problem Solving 3-19 E
(Sem-1 &2))
Iteration and Loops
& 2) b Runtime initialization An array can be explicitly initialized at
:
3-18 E (Sem-1 operations of runtime. This approach is usually applied for initializing large arrays.
an array ? Explain about various For example, consider the following segment of a C program :
Que 3.22. What is
=
an array. for (i 0;i< 100; i=i+1)
of same data tyDe ;
Answer number of elements
a of finite if i<50
An array is listetc. sum[i] = 0.0;
1
integers, arraydeclaration is as follows:
strings * assignment statement */
else
2 Syntax of array_name[size of array]; performed on linear, structure i.e., sum[i] = 1.0;
Data type arrays: The operations
Operations on array or list.
arrays are: element in the value
o

Traversal:
Processing each
of the element
with a given
1
the location The first 50 elements of the array sum are initialized to zero
Search : Finding while the
list.
a given key. Adding a new element to the list.
remaining 50 elements are initialized to 1.0 at runtime.
Insertion :Removing an element from the 2 Two-dimensional arrays:
Deletion : Arranging in some type of order, ascending or Declaration of two-dimensioal array :
4
Sorting: the element a. Two-dimensional arrays are declared as follows:
5. a single list or array.
descending. or arrays within type array_name [row_size] column_size];
two lists
Merging: Combining declaro b. Two-dimensional arrays are defined
in much same manner as one
types of array with their
6.
dimensional array, except that a separate
Que 3.23. Explain various pair of square bracket is
required for each subscript. Thus, a two-dimensional array will
require two pairs of square brackets.
and initialization. C. Two-dimensional/arrays are
stored in memory, as shown in
Answer Fig. 3.23.1
type oflinp
Various types of
array : one-dimensional array is a Column
1, One-dimensional arrays :A one variable name using only one Column1 Column2
array, A list of items can be given one-dimensional array.
subscript and such a variable is called a
array : [OJ[1) [0J[21
Declaration of one-dimensional are used so that the
compiler Row 0 310
Arrays must be declared before they 275 365
memory.
in
can allocate space for themdeclaration is:
of array (1][0] [1](2]
The general form
type variable-name [size];
b.
containedin the n
Row
1

type of element that will be 10 325


The type specifies the size indicates the maximum
array, such as int, float, or char and the array.
can be stored inside the 2][01 (2][1] [2][2)
number of elements that
example : float height [50]; Row 2
For
arrays:After an array is
d declare, 405 235 240
Initialization of one-dimensional contain "garbage
initialized. Otherwise, they will
its elements must be the following stages: [3][0] (31[1] (3][2]
at either of
value". An array can be initialized : elemensu
We can initialize the Row 3 --
Compile time initialization variables when they 310 275 365
arrays in the same way as the ordinary
declared. Eig. 323.1. Representation a tw0-dimensional arrayi
of
n
memo
array is :

The general form ofinitialization of of valuesl;


array-name [size] = {list
type
Programming for Problem Solving 3-21 E (Sem-1 & 2)
Iteration and L0ops
:Two-dimensional arravs #include<conio.h>
3-20 E (Sem-1& 2)
two-dimensionalarrays declaration with a list of initial
main( )
Initialization of following their
by
may be initialized braces. For example, ; int ANJ[NI;
values enclosed in 0, 1, 1, 1,) second row ts
[3] = (0, 0, int B[NJ[NI;
int table [2] first row to zero and the
of the int C[NJ[NI;
the elements done row by row. arrays of three or
m

initializesinitialization
one. The
is
arrays : C allows compiler. The
gene int i, j, k, N;
Multi-dimensional determined by the clrser( );
The exact limit
is
multi-dimensional array is
:
dimensions. .... (size N]: printf("Enter the value of N");
[size1] [size2] arrav
form ofa array_name storedin the scanf("od", & N);
data_type Type of data to be printf(“ Enter the elements of matrixA:"; function
data_type: array Il to get matrix elements
where, array_name: Name of the of the dimension for(i = 0; i<N;i++)
..., size N : Sizes
sizel, size2, survey [3] [5](12];
are : int (31; for(j = 0; j<
N;j++)
[5], [4](5)
Some examples float table A {

two atrices (read size and


program to multiply scanf("%d", &Ai] (i]):
Write a keyboard).
Que 3.24.| from the
elemnent of natrices PAKTU 2017-18(Sem-1), Marks 071
number of
printf("Enter the elements of matriz B"); function get
OR
and for loopsWrite a for(i = 0; i<N;i++) / to matrixelements
format for while, do while 4+4 and store the
syntax of dimension
Write the
to multiply a matrix
C forj =
0;j<N;j)
program in
result inanother matrix. Marks 10
AKTU2018-19 (Sem-1),
{

scanf("%d, &BJUD:
OR user and
two 3 x3 matrix from thecommente
a program in C to input matrix form. (Write for(i=0;i<N;i).mltiplying 1 and 2nd
matrices and storing
Writemultiplication is the result in it in result
print appropriate places program).
in the Marks 0a forj = 0;
j<N;j++)
also at AKTU 2018-19(Sem-2),
OR
CiJj] = 0;
array and for(k = 0; k < N; k ++)
two 2-dimensional
Write a
program to find the product of
separate array. Marko10 CiJj] = CiiJ[j] + Ail k] * B[k]il;
print the output in AKTU 2021-22(Sem
2),

function to display the matrix


lfor(i =
Answer Unit-3. 0;i<N;i++)
Q. 3.2, Page 3-2E,
{

Syntax of while : Refer Unit-3. for(j = 0; j < N;j ++)


Refer Q. 3.3, Page 3-3E,
Syntax of do-while:
Q. 3.4, Page 3-4E,
Unit-3. printf("\t %d", Cli));
:
Syntar of for Refer
Program:
#include<stdio.h>
Iteration and Loops
Programming for Problem Solving 3-23 E (Sem-1 & 2)
3-22 E (Sem-1& 2)
printf("\n");

printf("\n"); getch();
return 0;
getch( ):
return 0; program
array. Write the
advantage of usingelements. PART-7
3.25.| Write the matrix
Que multiplication of two 2020-21(Sem-1), Marks10]
AKTU
Manipulating ArrayElements.
for matrix

Questions-Answers
Answer
using array
: type using a singl
Advantages of of the same Long Answer Typeand Medium Answer Type Questions
multiple data items
1.
Arrays represent randomly by using
the i
name. can be accessed
arrays, the elements for all :
2. In memory locationsallocated Que 3.26. Write a short note on manipulating array elements.
number. memory in contiguous memory being memorv t
extra i
Arrays allocate there is no chance of or shortage of
3 elements. Hence avoids memory overflow Answer
case of arrays. This 1 Once the array is declared and defined, individual elements of array can
arrays. be accessed in different ways.
Program : 2 The subscript in the square bracket indicates the position of element in
#include<stdio.h> the array.
#include<conio.h> 3. All array elements are numbered.
main() 4. The number starts with 0.
a[3][3];
5
In general form, the statement
int var_name = array_name{i);
int b[3] [31;
int x(3][3); is used to read data from an array, where subscript I indicates the
inti, j;
elements of matrix
a:"); position of array elements within the array.
printf("\nEnter the 6 The data type of variable and array must be same.
i++)
for(i = i<3;
0;

for(j = j<3;j++)
0;

scanf"%d",&all (l); PART-8


elements of matrix b:"):
printf"\nEnter the Using Multi Dimensional Arrays.
for(i = 0; i<3; i++)3;
for(j = 0;j< j++)
scanf("%d",&b[1 jl); Questions-Answers

for(i
= 0;
i<3; it+) Long Answer Type and Medium Agwer Iype Questions

for(j = 0;j <3;j++)


Que 3.27. What do vou understand by multi-dimensional arrays
x[i)G] = alili] + biJGJ; (array of arrays) ?
printf("%d",xilG);
Iteration and Loops Programming for Problem Solving 3-25 E (Sem-1 & 2)
3-24 E (Sem-1 & 2) :
String handling functions
can There are large numbers of string handling functions that can be used
dimensional) arrays and
1
to carry out many of the string manipulations.
Answer an array of 1-D (i.e., singlecolumns. Bach row is a singlo
A 2-D
array is rows and 2
These functions are packaged in string.h library.
1.
as a plane that has
be visualizedarray. visualized as a cube thet 3
Following are the most commonly used string handling functions:
dimensional
array of 2-D
arrays and can be
an
2
A3-D array is array.
plane is a 2-D any level and in general, ann-D
arrav Method Description
has planes. Each
can scaled up to strcat() It is used to concatenate(combine) two strings
be
3 This concept - arrays. not neerod
is an array
of (n 1)-D three are generally
higher thanapplications are to be develoned strlen) It is used to show length of a string
dimensions
Arrays having highly data-extensive
unless and until dimension 3 strrev() It is used to show reverse of a string
matrices of
Write a
program to add two strcpy() Copies one string into another
Que 3.28.|
another matrix. It is used to compare two string
and store the result in 2017-18(Sem-2), Marks 07
AKTU
strcmp)

PART-10
Answer
3-22E, Unit-3. Structure.
Refer Q. 3.25, Page
PART-9
Character Array and Strings. Questions-Answers
Long Answer Typeand Medium Answer Type Questions
Questions-Ansvers
Questions
Medium Answer Type
Long Answer Type and Que 3.30. What do you mean by structure ? How we define
and
declarea structure variable ?
array. State
Que 3.29. Write a short note on string and character Answer

some library functions for string manipulation. 1. Structure isa user-defined datatype which allows us to combine data of
different types together. Structures are used to represent a record.
OR
Marks
05
2. Structure use struct keyword to hold the information of structure
on string. AKTU 2018-19(Sem-1), member or elements.
Write a short note
3. The general syntax of a structure definition is as follows:
Answer Struct tag_name
of characters that is treated as a single dataiten
1 String is a sequence
and terminated by null character\0'. data_type member 1;
a type.
C
language does not support strings as data data_type member 2;
3
A string is one-dimensional
array of characters in C language.
programs.
readable sincludíng
4 These are often used to create meaningful and characters
contains 12 endof
For example: The string "hello world" compileratthe
"10'character which is automatically added by the
the string.
Iteration and Loops Programming for Problem Solving
3-26 E
(Sem-1& 2) 3-27 E
(Sem-1& 2)
type of data.
structure may belong to a different
4, Each member in the :
student = (60, 180. 75):
Declaring structure variables
subsequently to declare variables
that have
may be used
1. The tag_name
the tag's structure.
elements: In the given program the value 60 is assigned to
2. It includes the following student.weight and
180.75 is assigned to
The keyword struct. one corresponding student.height at compile time. There is a one-to
name. between the members and their initializing
b. The structure tag commas. values.
ofvariable names separated by Oue 3.32. Write difference
C. List between structure and array. Write a
semicolon.
d A terminating program in Cto find the largest
:
variable is as follows element of a 4*4matrix,
3. Declaration of structure OR
struct book bank Write a program in C to find the largest number of elements
in
4 * 4 matrix, AKTU2017-18(Sem -2), Marks 07
title[20] ;
char
author [15]; OR
char Differentiate structure and array.
pages;
int
float price; AKTU2017-18(Sem-2), Marks
3.5|
book2, book3; Answer
struct book_bank bookl, as variables oftros Difference between structure and array :
book1, b0ok2 and book3
Here, the structure declares
these variables has four members
struct book _bank. Each of
structuno
How to access structure members ? Discuss 1 Structure is,a collection An array is a collection of
of
Que 3.31.| related
logically reláted dataitëms of
initialization. different
data elements of same type.
data types:

Answer 2. Structure
is a
user-defined| An array is a derived data type.
: data type.
Accessing structure members order to make them
are linked to the structure variables in
Variables structure needs to be first An array behaves like
1. 3.A designed abuilt-in data
meaningful members. a variable is established using
the anddeclared beforetype as we need to simply
declare
2. The link between a member and as operator or period the variables of that type can an array variable and use it.
known 'dot
member operator which is also be declared and used.
operator'. For example, 4
For example: For example :
bookl.price can be used for any struct test
the price of bookl and int a[3] =(1,2, 3};
is the variable representing
other ordinary variable. int a;
:
Initialization char b;
A structure variable can be initialized at
compile time.
float c;
For example :
main () struct test t1;
t1.a = 99;
struct t1.b=c;
tl.c= 88.79;
int weight;
float height;
Iteration and Loops Programming for Problem Solving 3-29 E
(Sem-1 &2)
3-28 E (Sem-1 & 2) #include<conio.h>
Program : struct date
#include<stdio.h>
#include<conio.h>
main) int day;
{
int month;
static int a[4][4;gr;
int i,j,
1 col, elements ofmatrix:"): int year;
nrintf«nEnter the
pr < 4; i++)
for(i = 0; i yoid main()
for(j = 0;j<4;j++)
{

struct date d1,d2;


scanf("%od",&alil ji);
clrscr);
printf("Enter first date(dd/mmyyyy):");
gT = a0][0]: scanf("%d %d%d",&d1.day, &dl.month, &dl.year);
row = 0; printf(“\nEnter second date(dd/mmyyyy):");
col = 0; i++) scanf("%d%d%d",&d2.day, &d2.month, &d2.year);
for(i = 0;= i<4;< 4; j++)
I forj 0;j if(d1.day == d2.day) & &(d1.month:T

d2.month) &&
(dl.year == d2.year))
iflalil li] >gr)
printf("\nEqual");
alilli1;
gT = else
row = i; printf("\nUnequal")
col =j;
getch);

%d",gr); Que 3.34. Write a program in C to create, a database of fifty


printf(Largest element is =%d",row, col):
row=%d and col
printf("\n and is situated at students to store personal details such as roll number, name and
marks. Printall the details of students whose name is entered by
getch);
return 0; the user. AKTU 2017-18(Sem 2), Marks 07
a program that Answo
Que 3.33. Define
structure with syntax. Also write
use structure say datedates
that #include<stdio.h>
compares two given dates. To store date year. If the struct student
month and
namely date,
contains three members message as Equal" otherwise
Unequal
char name [50];
are equal then display 2017-18(Sem-1), Marks0 int
AKTU roll;bo
float marks;
}s;
Answer Unit-3. int main()
: Q.3.30, Page 3-25E,
Structure with syntax Refer int i;
Program :
#include<stdio.h>
Iteration and Loops Programming for Problemn Solving 3-31 E (Sem-l & 2)

2) #define SIZE 10
3-30 E (Sem-l &
information:\n"); struct bookdetail
printf"Enter
i++){
for(i = 0;j< 50;
s[i].roll); char book_title(201;
slil.roll =i+1
number %d, \n", int number_of_pages;
print("\n For roll
print("\n"); float book_price;
}:
name: "); void output(struct bookdetail v],int n);
printf("Enter
&s(i].name);
scanf("%s", void main()
");
printf("Enter marks:
&si].narks);
scanf("%f, Information:\n"); struct book_detail b[SIZE];
printf("Displaying
int n, i;
50; ++i)
for(i = 0:; i< clrser);
%d\n", i+ 1); printf("Enter the Numbers of Books:":
printf("Roll number: scanf("%od",&en);
printf(Name: ");
print("\n");
puts(sli].name);
sli].marks); for(i = 0;i<n; it+)
printf"Marks: %f\n",
printf"\n");
printf("|tBook %dDetail:=\n",i + 1);
printf("\nEnter the Book Title:\n"):
return 0; A
Scanf("%s";bi).book_title):
of: structure
C
programming printf("Enter the Pages of Book:\n");
Explaintheimportance in scanf("%d",&bli].number of_pages);
Que 3.35.
enter and print the recori
C using structure to may includei printf(“Enter the Price of Book:\n");
Write a program in your library. Following fields be
of 10 books available in and number_of_pages. scanf("%f", &bli).book_ price);
book_price
in the record book_title,
:
Marks 07
AKTU2018-19(Sem-2),
output(b, n);
getch);
Answer
Importance structure in programming:
of
C
data
void output(struct bookdetail v), int a)
of different
Cprogramming, structure allows to store variable
manipulate data
m
{
In
makes it easier to
1.
typesinto a single entity that int i, t = 1;
program.
and saves tine.
=
for(i 0;i<n; i++, t++)
Structure in Cprogramming
increase reliability
Z.

Program : printf("\n);
#include<stdio.h> printf("Book No.%d\n",t);
#include<conio.h>
include<string.h>
Iteration and Loops Programming for Problem Solving 3-33 E (Sem-1 & 2)
3-32 E (Sem-1 & 2) is=%s
\n",t,v[i).book_title):
printf(4\t\tBook %d Title\n",t,vil.number_of_pages): char c;
is=%d )It1;
printf(“lt\tBook %d Pages Price is=%f \n",t,vi].book_price): This declares a variable It1 of type union
printf("lt\tBook %d a. item.
b. This union contains three members each
printf("\n"); with a different data type.
Que 3.37. Differentiate structure and union in C. Write a C
program to store the student
detail using union,
PART-11 Answer
Union. Difference between structure and union:
S.NO Structure Union
Questions-Answers 1. A structure is a collection is a user-defined data type that
logically related data items ofIt
of refers to a memory location using
Questi
Answer Type different data types.
Type andMedium
several types.
data
Long Answer
2. Each member has its own
storage location. All the members have the same
storage location.
AKTU 2018-19(Sem-2), Marks 07
union.
Que 3.36. Explain
3. All the members of Only one
structures can be accessed at accessed member of union can be
any time. at a time.
memory location using
referss to
a
Answer
user-defined data type that
1,
Union isa 4. Syntax of structure Syntax of union:
several data types. structures. struct item
conceptually similar to union item
2.
Unions are union keyword.
A union is
declared using the memory location which is int m; int m;
members uses a single shared float x;
tloat x;
4. In union each largest data member. : char c; char c;
equal to the size ofits as follows
union declaration is storage location in memorystorage location memory :
5 The syntax of in
nmame 1200 1201
union m

1680 1681
data typel memberl;
1682 1683 1000 1001 1002 1003
X

1500

data typeN memberN; m


variable_name2......;, Total 7 bytes
variable_namel,
Total 7 bytes
For example:
union item

int m;
float x;
Iteration and Loops Programming for Problem Solving
3-35 E (Sem-1 & 2)
3-34 E (Sem-1 & 2)
union item u;
5. structitem s; u.m = 4; Questions-Answers
s.m = 4; u.X= 386.9:
S.x =386.9; printf("%d", u.m); Long Answer Type and Medium Answer Type
because the uestfons
printf("%d", s.m); error There will be error
There will be
no in current]v
storage locationweiscannot
ofm.
print
printing the value assigned to x. So,
m. Hence, only one Oue 3.38. What is enumerated
data type ? Write a
the value of accessed at a time program to
C

member can be display month in the year using enum.


: OR
union Write a short note on enumerated
student details using data type.
Program to store the
#include<stdio.h> AKTU2018-19(Sem-1),
#include<conio.h> Marks 05|
OR
void main() Explain enumerated data types. AKTU 2018-19(Sem-2), Marks 07
struct student
Answer
char name[30);
char sexX;
int rollno;
float percentage;

union details
es 1.

3.
4
Enumeration (or enum) is a user-defined

The keyword enum is used to


Enum declaration is a follows declare
enum flaglconstant1,
data type in
It is used to assign names to integral cónstants
easy to read and maintain.
C.

which make a program


new enumeration types

constant2, constant3,
Variables of type enum can be
...
J;
in C.

struct student st: 5.


defined in two ways:
a. enum week{Mon, Tue, Wed);
union details set;
enum week day;
printf(Enter details:");
name: "); b.enum week{Mon, Tue, Wed)day;
printf("\n Enter For example :
scanf("%s", &set.st.name); #include<stdio.h>
no: "): enum week{Mon, Tue,
printf("\n Enter roll Wed
Thus, Fri, Sat, Sun);
scanf("%d, &set.st. rollno); int main(0
flushall);
printf“\n Enter sex: "); enum week day;
scanf("%c", &set.st.sex); day = Wed;
printf"\n Enter percentage:"); printf("%d",day);
scanf("%f, &set.st.percentage); return 0;
print"\n The student details are: \n");
printf(“\n name:%s', set.st.name); Output:
printf"\n Rollno :cd", set.st.rollno); 2
printf"\n Sex:%c,set.st.sex); Program to display months
set.st.percentage); #includeKstdio.h> in the year using enum :
printf"\n Percentage :%f", #$include<conio.h>
getch); void main(void)

enum monthljanuary=1,february=2,march=3,april=4,may=5,
PART-12
Enumerated Data Types.
Iteration and LDops Programming for Problem Solving
3-36 E (Sem-1 &2) 3-37 E (Sem-1 &2)
june=6,july=7,august=8,september=9,0ctober=10, int subject2;
november=11,december=12); int subject3;
printf("Here are the months name`);
printf("jan:\t%d\n"january); main()
printf(“feb:\t%d \n",february);
printf("mar:\t%d \n",march); struct marks student[3] =
printf("apr:\t%d\n",april); ((45,68,81),
This declares the student(75,53,69),
as an array
(57,36,71}:;
printf("nmay :\t%d\n",may); of three elements student[0],
printf("jun :\t%d\n" june);
student[1], and student [2]
and initializes their members as follow:
student[0].subjectl = 45;
printfjul :\t%d\n"july);
printf("aug:\t%d\n",august); student[O].subject2= 68;
printf("sep:\t%d \n",september);
printf("oct:\t%d\n",october):
printf("nov :\t%d \n",november); student[2].subject3 =71;
printf"dec:\t%d \n",december); The array student actually
looks as shown in Fig. 3:39.1.
getch(); student[0].subject1
45
.subject2 68
PART- 13 .subject3 81
student[1].subject1
Arrays of Structures. 75
.subjec+2 53
.subject3
student[2].subject1 69
Questions-Answers 57
.subject2 36
Type Questions
Long Answer Type and Medium Answer subject3 71
Fig, 3.39.1. The arr
array student inside memory.

Que 3.39. Write a short note on


array of structures.
PART-14
Passing Arraysto Functions.
Answer same structure is to be
1. An array of structure is defined whenever the
applied to a group ofitems, elements. Questions-Answers
structure in itself.
2. In array of structure each element is the
In array of structures each element of the
3
array represents a structure Long Answer
iong Type and Medium Answer Type
variable. Questions
Array ofstructure can be declared as
:
4

struct class student[100]; Que 3.40. How to pass


100 elements. Eaci array to
defines an array called student, thbat consists of functions ?
is
element defined to be of the type struct class. Answer
memory in the same wey
5. An array of structures is stored inside the
a multi-dimensional array. Wnenever we need to pass a
Glanguage, it is done list of elements as argument to any
For example: Consider the following declaration
:

by passing an array to function in


This can be done function.
struct marks in following ways:

int subjectl;
3-38 E (Sem-1 & 2) Programming for Problem Solving
3-39 E (Sem-1& 2)
Passing arrays as parameter to function:
array element as argument to a function. b In the function definition, we must
indicate
1,
In
a
this, we will pass single dimensions by including two sets that the array has two
The size of the second dimension of brackets.
a.

For example : C.
d. The prototype declaration must be specified.
#include<stdio.h> should be similar to the function
void giveMeArray(int a); For example : header.
int main() #include<stdio.h>
void displayArray(int arr(2] [2);
= 4 );
int myArrayl] (2, 3,
giveMeArray(myArray[2);
int main()
only.
IIPassing array element myArray[2]
int arr(2] [21, i, j;
return 0; printfPlease enter 4 numbers for
for (i = 0; i < 2; ++i) the array: \n"):
void giveMeArray(int a)
for (j = 0; j < 2; ++j)
printf"od", a);
scanf("%d", &arrilG1):
:
Output
4
Passing a complete
one-dimensional array to a function:
necessarv
2. pass one-dimensional array to a called function, it is 42ll passingthe array as argument
a. To array, without any subscripts and the size of displayArray(arr);
to list the name of the return 0;
array as arguments.
For examnple : void displayArray(int arr(21
#include<stdio.h> 21)
float findAverage(int marks ); int i,j;
int main() printf("The completearray
for (i = 0; i2; ++i) is: \n");
float avg
= 95);
int marksl (99, 90, 96, 93,
avg = findAverage(marks); printf("\n); M
getting cursor to new
I/ name of the array is passed as argument. for (j=0;j<2; ++j)
line
printf("Average marks =%.1f", avg);
return 0;

float findAverage(int marksl)


printf("%d\t", arr[il6); itisused to provide tab space

int i, sum =0;


float avg;
= 0;
Output :
for (i i<=4; it+) {
Please enter
4 numbers for
sum += agelil; 1
the array :
avg = (sum /5);
return avg;
The complete
12
array
Output: 34
is:
94.6
Passing a multi-dimensional array to a function : name.
a The function must be called by
passing3 only the array
4-2E (Sem-1 &&
2)
Functions

PART-1|

4UNT Functions
Function : Introduction.

Questions-Answers
Long Answer Type and MediumAnswer
Type Questions

Que 4.1. Discuss function with example.


What are the benefits of
CONTENTS usingfunction ?
Answer
: Introduction. 4-2E to 4-3E 1. A function is a set
Part-l : Functions of statements
computation and produes output. that take inputs, do some specific
4-4E to 4-7E
Part-2 : Types of Function 2 The idea is to put some commonly or
4-7E to 4-8E make a function, so repeatedly done task together
that instead of writing the same and
Part-3 : Functions with Array again for different inputs, we can code again and
...... 4-85 to 4-14E call the function.
Functions,
to Example:
Part-4 : Passing Parameters Reference
Call by Value, Call by #include <stdio.h>
.... 4-14E to 4 17E IlAn example function takes two parameters
Part-5 : Recursive Functions Il as input and returns that
maxof two 'x andy
.... 4-17E to 4-27E int max(int x, int y) input numbers
Part-6 : Basic of Searching and Sorting
Algorithm : Searching & Sorting
Algorithm (Linear Search, Binary
if(x>y)
Search, Bubble Sort,
return x;
else
Insertion and Selection Sort)
eturn y;
ll main function that does not receive any
Il returns integer. parameter and
int main(void)

int a = 10, b = 20;


/ Calling above function to find max of
int m = max(a, b); 'a' andB
printf[("m is %d",
m);
return 0;
Output :
mis 20

4-1E (Sem-l & 2)


4-3 E
(Sem-1& 2)
Programming for Problem Solving 4-4 E (Sem-1 & 2)
Benefits of using functions : Functions
our program's structure.
1. It provides modularity to name
have to call the function by its
2 It makes our code reusable. We just PART-2
to use it, wherever required. Types of Function.
3
In case of large
programs with thousands of code lines, debugging and
editing becomes easier if we use functions.
program more readable and easy to understand. Questions-Answers
It makes the
Long Answer
? 1ype and Medium Answer
Que 4.2. How function is declared Type GQuestions

Answer Que 4.3.


What are the types
General syntax for function
declaration is, of functions ?
1.
returntype functionName(typel parameter1, type2 parameter2,.): Answer
before i.
2. Like any variable or an array, a function must also be declared There are two types
of
is used. nom 1, Standard library functionsin C programming:
Function declaration informs the
compiler about the function a. The standard functions (built-in functions) :
3 type. library
Drogramming to functions are built-in
parameters it accepts, and itsreturn handle tasks suchas mathematical functions
in C
The actual body ofthe function
can be defined separately. It is also called IO processing, string handling etc. computations,
4 b
These functions are
as function prototyping.
of following four parts: the header file, thesedefined in the header
functions are availablefile. When we include
5. Function declaration consists C. For example, printf) a for use.
output is standard library
a. returntype :
some sort of calculation to the screen function to send formatted
When a function is declared to perform defined in "stdio.h" (display output on the screen). This
at header fle. function is
or any operation and is expected to provide with söme result There are other numerous
at the end
the end., iu such cases, a return statement is added such as scanf), library functions defined
under"stdio.h,
of function body. our program, printf), getchar() etc. Once we include
double) 2. all these functions are "stdio.h" in
returntype specifies the type of value (int, float, char, User-defined
functions: available for use.
to return to the program which called a. The
that function is expected functions created
b. Depending upon by the user are called
the function. user-defined functions.
we can the complexity andrequirement
b. functionName : create as many user-defined of the program,
functionName is an identifier and it specifies the
name of the C.The execution of a C program functions as we want.
i. d When begins from the main() function.
function.
the compiler encounters functionName();
function, control inside the main
and therefore
must
of the program jumps to
ü. The functionName is any valid Cidentifier language.
shown void functionName) as
variables in C
follow the same naming rules like other
#include <stdio.h>
Parameter list : void functionName)
The parameter list declares the
type and number of argumenis
that the function expects when it is called. argument
The parameters in the parameter list
receive the referred as int main()
are often
values when the function is called. They
formal parameters. a statemen
semicolon is statement functionName);
d
Terminating semicolon : The where the
out
terminator in to help the parser figure
C

ends.
4-5E (Scm-1 & 2) 4-6 E (Sem-1 & 2) Functions
Solving
Programming for Problem Reusable codcs that can be used in other programs.
2
functions ? Give
What are the types of user-defined A large program can be divided into smaller modules. Hence, a large
project can be divided among many programmers.
Que 4.4.
user-defined function.
advantages of
Que 4.5. Write about the formatted and unformatted
Answer on wvhether arguments are present input/output function in C.
followine
function, depending not, may belong to one ofthe
A user-defined is returned or
not and whether avalue Answer
value : Eormatted I/O function :In order to write a user interactive program in C
arguments but no return
categories:
with function language, we would need input and output functions that are also called
Function from the calling
function receives the data
1

Here the called match in number, data type routines. The two functions used for this purpose are :
parameters should
a.
:

The arrguments
and The printf() function
back to
%

The printf() function is an important function to show the formatted


and order. not return any value
1,

But, the called function does data in its scope only. output on the standard output device such as monitor screen.
C. Instead, it prints the
calling function. calling functio 2
The general form of printf() function is:
way communication between the
It is a one data printf( “format strings", argument list);
function.
and the called value: The scanf() function :
arguments and return b
2 Function with no not receive any data
from the callino 1 The scanf() function does the opposite of printf() function. reads
It
Here, the called function does data entered from the keyboard and sends it to the memory of the
a.
function. carry out the specified task CPU.
manages with its local data to returme 2 It will read only till the next white space character (i.e.,'\n' or \t'
b It processing, the called function or") and thus can be used to read only one word as a string should
However, after the specified function.
C. to the calling be highlighted.
the computed data between the calling funcion
one way data communication Unformatted I/O functions: These functions deal with a single character
d. It is alsoa or with a string of characters.
function.
and the called
arguments and one return value: Character input : Three input functions available in most C language
Functions with calling function through compilers are:
The function value receives data from the
a. back any value. Getchar0:This function reads one character from the keyboard after
arguments, but does not send
A.
at the terminal. the new line character is received (when we press enter key.)
Rather, it displays the
results of calculation
result of a function
wish to have the b. getch() and getche() :
However, we may not always
displayed. processing.
1
These two functions are very similar, as they respond without
We may use it in the
calling function for further programs, pressing the enter key.
C
of portability between
Moreover, to assure a high degree any IO 2 The difference is that with the function getche(), the echo of the
involving
d be coded without pressed key is displayed on the screen (the letter e" stands for
a function should generally "echo"), but with the function getch), there is no echoing.
operations. :
Functions with no
arguments and no return value naracter output:The programming language C contains functions which
4. any data from the calmy can handle characters, while processing a file.
These functions are
Here, the called function
does not receive calling functou
return any data back to the Putchar) : The function putchar() (stands for put character") uses
function. And, it does not a

no data transfer between the calling functiou SINgle argument, that can be a character variable or the character itself
b. Hence, there is but enclosed in single quotes.
the called function.
Advantages of user-defined function:
easier to understand,
maintain and debug
1ne program will be
1
4-7 E (Sem-1 & 2) 4-8E (Sem-1
Programming for Problem Solving & 2)
can be Functions
for files, but its output
b Putc() : The function putc() is intended
like the screen (stdout) or the printer
4. Deletion:
redirected to any standard device
In delete operation, the element which
(stdprn). The function putc()
takes the following form searched (using linear search) and already exists in the array is
deleted, followed by the shifting
putc (a, device): of elements.
The user enters the position of the element
PART-3 from the array. which is to be deleted
Functions with Array. Deletion operation,just like the
insertion operation, does not affect
the size of array.
iv. Also, the position
of the element to deleted should
Questions-Answers size of array, since the deletion be be within
array is not possible. of an element beyond the sizethe of
Answer Type Questions
Long Answer Type and Medium 5. Sorting:
i. This operation is performned to sort an array
either ascending or descending. into a fixed order, ie.,
of array ?
Que 4.6. What are the different functions
PART-4
Answer Passing Parameters to Functions, Call
by Value, Call by Reference.
on arrays :

Different functions that can be performed


Traversing :
1 of an arrav Questions-Answers
Traversing an array means going through each element
go
once. We start from the first element and the last
exactly Long Answer Type and Medium
element. Answer Type uestions
2 Searching:
The search operation is used to find
a particular data item or element
in an array. We can perform searching in
an unsorted array with Que 4.7. Explain parameter and
its types. How can we pass
the help of traversal of the array. parameter to function ?
can
The linear traversal from the first element to the last element can
to
be used search if a given number is present in an array and Answer
also be used to find its position if present. 1. Parameters are variable used in function
element definition.
iiü This is done by comparing each element with the given 2
Parameters must be written within
(which is to be searched). Once the element is found, the search function in function definition.
parenthesis followed by the name of
operation is stopped. 3 "There are two types of parameters
3. Insertion : and they are as follows
:

array. a.
Insertion operation is used to add a new element in the Actual parameters: The actual parameters are
that are specified in calling function. the parameters
When we specify the particular element and position where 1t151
be added in the array, we perform insertion operation. performíng b. Formal parameters:The formal parameters are
that are declared at called function. the parameters
iüi. However, disturbed while
the size of the array is not 4

this operation. Wnen a function gets executed, copy of actual parameter


sufficientspace copied into formal parameters. the values is
iv An element will be inserted in an array only ifit has cannot
to add it. Ifthe size of an array isfull already, a new element
be added.
4-9 E (Sem-1 & 2) 4-10 E (Sem-1 &
2)
Solving Functions
Progranmming for Problenm
: function There is no copying ofvalues since their memory locations are
mechanism
Parameter passing one function to another referenced.
mechanism ofpassing values from function to ii. If any modification is made to the values in the called function,
It is a parameters from calling
a.
two methods to pass the original values get changed within the calling function.
There are follows:
b
called function and
they are as For example:
1, Call by value
:
ofargumentsis passed from the calling function #include<stdio.h>
When the value are copied into the called main()
i function, the values
to the called int num[20], i, max;
function. called function
are made to the values in thewithin the calling printf(“Enter the size of the array :\n");
If any changesno change in the original values scanf(“%d", &max):
then there is printf (“Start entering the number\n");
function. for(i = 0; i< max; i++)
example :
For
#include<stdio.h>
()
scanf (“%d", &num[il);
main
sort_nums (num, max); *function reference*/
int nl, n2, x; printf("Sorted numbersare as follows\n");
int call_by_val (); for(i = 0; i <max; it+)
nl ==6; printf("%3d", num[il);
n2 9; =%d\n", nl, n2) ; )*end of main()*/
printf ("nl = %d and n2
x= call_by_val(nl, n2); ; * function to sort list of numbers*/
n2)
printf("nl =%d and n2 =%d \n", nl, void sort_nums(a, n)
printf("x =%d", x); int al, n;
Fend of main ()*/
to illustrate call by value*/ int i,j, dummy;
* function
_by_val(p1, p2) for(i =
0; i<n-1; i++)
call
int pl, p2;
for(j =i+ 1;j<n;j++)
int sum;
sum = pl + p2; if(ail > a61)
pl + = 2:
p2 += pl; ;
dummy = ail;
printf("pl=%d and p2 = %d\n", pl, p2) alil =ajl;
return (sum); ali] dummy;
}
*End of if$/
Output: *End of j for loop*I
nl=6 and n2 = 9 *End ofi for loop*/
return:
pl =8 and p2= 17 )/*End offunction*/
nl =6 and n2=9 Output:
x= 15 Enter the size of
There is no change in the values
of n1 and n2 before and atte the array:
the function execution. Start entering the numbers:
2 Call by reference : their 44
instead:
the actual values are not| passed,
In this method, 64
addresses are passed.
& 2) 4-12 E (Sem-1 & 2) Functions
4-11 E (Sem-1
Problem Solving
Programming for t=*X;
*x= *y;
16 are as follows : *y = t;
Sorted numbers
16 Oue 4.9. What is a function ? Why programmers use functions
44 referenoo
64 value and call by in code ? While executing a function, how the values are passed
youmean by call by call hy ?
What do using
two numbers above stoto between calling and called environment
Que 4.8. swapping
Write an algorithm
for a C program for the AKTU 2018-19(Sem 1), Marks 10
techmigue. Also write 2018-19(Sem-1), Marks 07
reference LAKTU
algorithm. Answer
4.7, Page
4 8E. Unit
a
Function and its use : Refer Q. 4.1, Page 4-2E, Unit-4.
Answer : Refer Q. Execution of a function : Refer Q. 4.7, Page 4-8E, Unit-4.
call by reference
Call by value and Oue 4:10. Explain the difference between parameter passing
Algorithm
l:Start mechanism call by value and call by reference. Which is more efficient
Step
Step 2: Set
a - 10 and b
function swap
(&a,&b)
+ 20
and why ? AKTU 2017-18(Sem-1), Marks 07

ries
Step 3: Call the
function OR
a:Start
b:Assign t **
Differentiate between call by valueand call by reference with proper
c:Assign *+*y example. AKTU 2021-22(Sem-1), Marks 10
d:Assign
y t
e:End function
x
Step 4:Print andy Basis Call by
s.No. value Call by reference
Step 5:Stop
Program : 1 Descriptior A
function which passA function which do not
#include<stdio.h>
actual data or value to pass actual data or value
#include<conio.h> to other function.
function other function.
void swap(int *,int
*);
/ Declaration of
void main() 2.ArgumentsA copy of actual argument Reference to the location
or address of actual
is passed to respective
formal arguments. arguments is passed to
int a = 10, b=20; formal arguments.
clrscr);
3. Value Original value is not Original value is modified.
printf("Before swapping \n");
a, ); modification modified.
printf( "a= %d \n b= %d\n", b
/ Call by reference Changes Changes made inside the Any changes made in
4
Swap(&a, &b);
printf("After swapping \n"); function are not reflectedformal arguments will
a,
printf( 'a =%d\n b= %d\n", b); on other functions. also reflect in actual
getch();
arguments.
5. Memory Actual and formal Actual and formal
void swap( int *x, int *y) location arguments will be created | arguments will be created
in different memory. in same memory location.
int t;
4-13 (Sem-1&2)
E

4-14 E (Sem-1 & 2)


Functions
Solving
Programming for Problem : Refer Q. 47
by reference Difference between global variable and extern variable:
value and calI
Examples of call by S. No. Global variablesExtern variables
Unit-4. :
Page 4-8E, more efficient
because functiex
is are not refiected on other memo 1. Global variables are defined| Variables that are both alive and
Call by value the function
inside different only once in any of the active throughout the entire
Changes made created in program module and they program are known as extern
1, arguments will be
Actual and formal can be accessed by all others. variables.
2

location. not required. 2. Memory is allocated. No memory is allocated.


Knowledge ofpointer is
:
Differentiate between
Que 4.11. arguments PART-5
formal variables
Actual and extern Recursive Functions.
Global and
2. argumente.
Answer arguments and formal Questions-Answers
actual Formal arguments
Difference between
arguments Long Answer Type
andMedium Answer Type Questions
Actual parameters are writtenin
S. No. are Formal and
arguments that are the function prototype
1. The call
function of the definition.
function header
passed in a arguments.
called actual The formal
arguments are defined Que 412. What do you mean by recursion ? Illustrate the use of

These
arguments are in function
declaration. recursive function with an example in C language.
function.
defined in calling
2. are local
Formal parameters
each are assigned Answer
At the time of
the call, variables which
3. parameter assigned| values from the arguments when
is
1
Recursion isa programming technique that allows the programmer to
actual express operations in terms of themselves.
corresponding formal is called.
to the the function Recursion function is a function that calls itself.
parameter in the function 2.

definition.
3. Recursive functions can be
effectively used to solve problem where
Example: solution is expressed in terms of successively applying the same solution
4
Example
:
void main () to subsets of the problem.
void main () When we write recursive functions, we must have if statement
int num 1; somewhere to force the function to return without the recursive call
int num 1; display (num 1); being executed. Otherwise, the function will never return.
display (num 1); 5 The factorial of a number n is expressed as a series of repetitive
para 1)
void display (int multiplications as:
void display (int
para 1) =
factorial ofn n(n- 1)(n–2)........
For example,
=4 x3 x
factorial of 4
1=24
parameter A function to evaluate factorial of n is as follows :
para l is formal
num 1 is actual parameter factorial (int n)
nch

4-16 E (Sem-1 & 2) Functions


4-15 C (Scm-1 & 2)
Solving
Programming for Problem OR
Write a program to print the Fibonacci series using recursive
int fact; function. Take the limit from the user as input,
if (n == 1)
return(1); AKTU 2021-22(Sem-2), Marks 10
else (n- 1); OR
fact = n*factorial Define recursion. Write a program to find sum of Fibonacci
return (fact): series
using recursion. AKTU 2021-22(Sem-1),Marks 1Ó
? Explain in
detail
are the principles of recursion Answer
Que 4.13. What
Recursion : Refer Q. 4.12, Page 4-14E, Unit-4.
algorithms with Program to generate Fibonacci series using recursion:
Answer which are used
while designing #include<stdio.h>
Some basic
principles
int fibo(int);
recursion are: step: algorithms through
recursio int main()
1. Find the key with the design ofstep for the solution.
When beginning out the Key the
a.
one should try to find step, find out whether int num;
we have executed the key solved in the same way. and int result;
Once problem can be
remainder of the printf("Enter the nth number in Fibonacci series: "):
step, ifnecessary. scanf("%d", &num);
modify the
a stopping rule
: or a substantial part of if (num <0)
2 FindThe stopping rule indicates that the problem can stopped.
algorithmn be
execution of the
it is done and the the
printf("Fibonacci of negative umber is not possible.\n");
your algorithm:
key step for the
problem and finding two
3 Outline After determining the step is to combine these
a. cases which are to be handled, the next else
them.
using an if'
statement to select between recursion are now to be
program the procedure for result = fibo(num);
b. The
main and stopping rule applies.
step through until the printf"The %d number in Fibonacci series is %d\n", num,
written to carry the key result);
: always
4 Check termination taken to ensure that the recursion will rule return 0;
Care should be steps and the stopping
a. number of
terminate after the finite
should also be satisfied. extreme cases correctly. int fiboint num)
b. It should also handle :the
5. Draw a recursion
tree algorithms is the recursion if (num == 0)
analysis of recursive
The key tool for the of memory that
the
determining the amount number
tree as it helps in size of tree reflects the return 0;
program will require and, the total total time needed
times the key step will be performed and the else if (num == 1)
of
for the program. the
Write ?
a program to print return 1;
Que 4.14. is recursion
What

Fibonacci series using recursion. 1), Marks() else


2017-18(Sem
AKTU
Fibonacci series.
return(fibo(num- 1) + fbo(num
OR -2));f 9.8 chN
Write a
recursive program in
C
to print
language2017-18(Sem-2), Marks 0
AKTU
4-18 E (Sem-1 & 2)
4-17 E (Sem-1 & 2) Functions
Solving
Programming for Problem 2 The search is said to be successfulif
the given element is found, i.e., the
a program to find the element does exists in the array; otherwise unsuccessful.
recursive function ? Write 3. There are two searching techniques:
Que 4.15. Define function. a. Linear search (sequential)
with recursive
AKTU2020-21(Sem-1), Marks 10
b. Binary
The algorithm which one chooses depends on search
factorial of a number organization of the array
elements.
5. Ifthe elements are in random order, then one have to use
technique, and if the array elements are linear search
4-14E, Unit-4. . sorted, then it is preferable to
Answer : Refer Q. 4.12 Page
use binary search.
using recursion
Recursive Function factorial of a given number Oue 4.17.
Program to find the Write down algorithm for linear/sequential
#include<stdio.h> search
)
technique. Give its analysis.
main(
n, Answer
int f;
clrscr( ); number:");. LINEARDATA, N, ITEM, LOc)
printf(“\nEnter any Tore DATA is a linear array with N
elements, and ITEM is a given
information. This algorithm finds
scanf("%d", &n); the location LOCof ITEM in DATA,item of
or sets
f= factorial(n); LOC: =
0 if
the search unsuccessful.
is
printf(“\nfactorial =%d"): 1. Insert ITEM at the end of DATAJSet DATA[N
Initialize counter] Set LOC:=1 +1]:= ITEM
getch( ); 2.
return 0; 3 (Search for ITEMJ
Repeat while DATALOC] ITEM
factorial(int n)
Set LOC:=LOC +1
(End of loop]
(Successful] If LOC=N+1,then : Set
if(n == 0) 4 LOC: =0
return(1): 5. Exit
Analysis of linear search:
else – 1)): 1.
Best case:The element occur at first
return(n factorial(n 0(1), position andthe time complexity
is
2 Worst case:The element occur
O(n).
at last positionand the time complexity
is
PART-6 & Sorting
Sorting Algorithm : Searching Que
4.18.Explain linear search and
Basic ofSearching and Search, Binary Seareh, Bubble Sort, binary search technique for
searching an item
Algorithm (Linear
and Selection Sort).
in a given array. Also write the complexity
Insertion each searching for
technique. AKTU 2018-19(Sem1), Marks05
Answer
QuestO Answers
lLinear search:
Questions Refer Q. 4.17, Page 4-18E,
Medium /Answer lype Binary search (A,
n, Unit-4.
Lang Answer IyYpe and Let A is an array n itemn, loc)
1 of number of items. item is value
beg to be searched.
2 end =0
you mean by searching ?
Explain. =n-1
mid = (beg +
Que 4.16. What do while (beg s end) /2
the 5. if end) and (a [mid)! =
elementin (item item))
6 end = < amid])then
AnsWer location ofgiven mid-1
process of findingthe
1. Searching the
is
linear array.
4-19 E (Sem-1 &2)
Solving
Programming for Problcm 4-20 E (Sem-1 & 2)
+ 1
Functions
7
else beg= mid 4. while i >0 and A[i] > key
8 mid = (beg + end) /2 5. do A[i + 1] +AE)
9. if(beg > end) then 6. i+i-1
10. loc =-1 =
7. A[i + 1] + key
11. else loc mid
Analysis of insertion sort :
1. Complexity in best case is O(n).
12, Ext O(log, n).
The complexity
ofbinary search is seava 2. Complexity in average case is
O(n).
What is difference
between sequential (linear) 3. Complexity in worst case is O(n2).
Que 4.19. Oue 4.21 Explain the selection
technique ? sort
and binary search with example.
Answer AKTU2020-21(Sem 1),
Binary search
Marks 10|
S.No. Sequential (Linear) search wite a program for the selection sort andOR
condition i.e., Elementary condition i.e.. explain it with example.
1. No elementary or unsorted. array should be sorted AKTU 2021-22(Sem
array can be sorted 2),
Marks 1o|
Tt takes less time to search an
to search an Answer
2. It takes long time element. Tn selection sort, we
1. repeatedly
element.
Complexity is Olog,n). in the array and move to findthe nextlargest (or Smallest) element
Complexity is O(n). it its final positionin the sorted array.
We can do this by swapping
2

3
It is based on divide and the element at the highest index
linearly. largest element. and the
4. It searches data conquer method. 3 We then reduce the effectiye
size of the array by one
repeat the process on the smaller element and
sub-array.
on 4 The process stops when the effective
you mean by sorting ? Write
a
short note array of1 element size of the array becomes 1 (an
Que 4.20. What do is already sorted).
Selection-Sort (A):
1

insertion sort. n+length[A]


2. for j6- 1 ton-1
Answer smallest j
(increasing for i-j+Tto n
Sorting: arrangement of data in desired format ifA l<A[smallest]
1 Sorting is a process of element then smallest
or decreasing). sorting is we can search any desired
that
7.
rotexchange (A,.1,A[smallest])
2 The usefulness of Analysis of
selection sort
efficiently. 1. Complexity in best case
place n is O(n).
Insertion sort: at the appropriate 2. Complexity in average case
we insert a particular value a[a] is inserted
in
Complexity in worst case is On).
In insertion sort, i.e., during kth iteration the element
3

1.
sublist, a [2], a[3] ...alk-1: is O(n).
the sorted sub-array a[1], 4.22. Discuss bubble sort.
proper place in the sorted comparing a[k] with alk -11, akfound
its accomplished by a Sak] is
2 This task is
the first element all such that+ 1]lj are moved oe Answer
on
alk-3] and so until elements alk 1, alk - -21, ali
position
Bubble
Sort procedure is
based on following idea:
3 Then each of the a[k] is inserted in + 1st 1
Suppose if the array
up and then element required to sort n,
contains elements, then (n
position -1) iterations are
array.
2,
ne set ofitems this array.
(A)
in the array are scanned again
Insertion-Sort dajacent items are and again and if any tWo
the end of the found to be out of order, they are reversed.
3. At
1. forj + 2 to length[A] position. first iteration, the lowest value is placed in the frst
do key -A1 A[1...j–1].*/
2.
into the sorted.sequence
*Insert A]
3. i-j-1
4-21 E (Sem-1& 2)
4-22 E (Sem-1 & 2)
Programming for Problem Solving
iteration, the next lowest value is placed in the for (j = 0; j < (num
Functions
4
At the end ofthe second
so on. -i- 1; j++)
second position and n dot
sorting large number of data items, For if (arrayil > arraylj +
5. It is very efficient in comparisons. 1)
n(n -1)/2
items, this method requires temp = arraylil;
Bubble sort (A):
1. for i- 1 to length [A]
forj -length[A] down toi+1
array[j] = arrayj + 1];
arrayj +1] = temp;
1]
ifA] <Aj-
4. exchange (A1, AU-1])
Analysis of bubblesort: printf("Sorted array is...
1. Complexity in best case is O(n).
case is O(n²). for (i = 0;i< num; i++) \n");
Complexity in worst case
2. average is O(n).
3. Complexity in printf("%d\n", arraylil);
program to sort set of integers inascending
Que 4.23. Write a C getch();
bubble sort technique.
order by using AKTU 2017-18(Sem-1), Marks
07

Que 4.24 What


OR do you understand by asymptotic
program. Describe important types of notations ?
concept and write the asymptotic notations.
Explain bubble sort AKTU 2021-22(Sem 2), Marks 10 OR
What do you mean by order
ofcomplexity? Explain various
to represent order of complexity notions
with diagram.
Answer Unit-4. AKTU 2018-19(Sem-1),
4.22, Page 420E, Marks 10
Bubble sort: Refer Q.
#include<stdio.h> 1.
#include<conio.h> Asymptotic notation is a shorthand way
and slowest to represent fastest possible
#define MAXSIZE 10
possiblérunning times for an algorithm, using high and low
bounds on speed.
void main() 2 It is a line that stays within bounds.
lMAXSIZEJ; 3 These are alsoreferred t0 as best case
int array used to find complexities of functions.
and worst case scenarios and are
int i,j, num, temp; Types of aymptotic notations
clrser; num \n"); 1.
0-Notation (Same order):
printf("Enter the value of This notation bounds a function within constant factors.
Scanf("d", &num):
one by one \n";h
b
We say fn) = 0g(n) if there
printf("Enter the elements exist positive constants n and c
C
such that to the right of n, the value of
for (i = 0;i <num; i++) fn) always lies between
Cgn) and C,gn) inclusive.
scanf("%d", &arraylil); Czgln)

fn)
printf("Input array is \n"); CI8a)
< num; i++)
for (i =0; i

printf("%d \n", arrayli);


ah fn) (gtn)
Bubble sorting begins */ Fig, 124.1.
for (i =;i num; i++)
<
4-23 E (Sem-1 & 2) 4-24 E (Sem-1 & 2)
Solving
Programming for Problem Functions
upper bound of an Little omega notation (o):It
bound):
0-Notation (Üpper method of expressing the asymptotically tight. isused to denote lower bound
that is
2
a.
Big-oh is formal
algorithm's running time.longest amount of time it could
measure of the
possiblv
olgln)) = fln):For any
positive
that 0 < cg(n)<fn) Vn n constant c> , if a constant n,> 0 such
It is the to complete. thers
f (n) and gn), if One 4.25.
b
take for the algorithm
non-negative functions, Explain selection sort
technique for sorting problem.
formally, for such that for all integers
More a constant
c
>0 Also Writean algorithm for
C.
an integer n, and
exists selection
umbers using selection sort technique sort. Sort the following
26, 54, 93, 17, 77, 31,
n2o f(n) s cgn) This is denoted as: 20. AKTU 2018-19(Sem-1),
44, 55,
big-ohofgn).
Then, f(n) is Marks 10
d.
f(n) e Ogn) as n gets large, grow faster th Answer
functions which,
i.e. the set of Solection sort and
its algorithm: Refer Q. 4.21, Page
constant time f(n). Numerical :
4 20E, Unit-4.
cgln)
26| 54 93 17
f(n) 77 31
44| 5520 93 is largest

26 54 20 17 77 3144 55 93
77 is largest

26 54 20 17 5531| 44| 77| 93


55 is largest
n
f(n) = 0(g(n).
1.24.2. 26| 54 20 17
Fig. 44 31 55 77| 93 54 is largest
:
2-Notation (Lower bound) a function within a constant
26 3120 1744|
a. gives a lower bound
This notation
factor. = Lgn)) if there are positive
for

constants and c such


cgn)
, 54| 55 77 93 44is largest
stays in place
We write fn) lies on or above 26
b the yalue off(n) always |3120 174454 55 7793
that to the right ofn,
31 is largest
f(n)

26 17
cg(n)t 20 31 44 54|55 77 93 26 is largest

20 17 26| 31 44 54| 55| 77 93 20 is largest

17 20 26 31 44 54| 55 77| 93 17 ok
f(n) = 2 (gn) that is Que 4.26.Write list is sorted
bound
Fig. 124.3. an
upper O-notationi3 a program theimportance
of sortingin
problemn solving. Write
used to denote
provided by in
using C
: is
:It upper bound bubble
4. Little-oh notation (o) constantn,>0
suel enteredby
the user.
sort technique to sort 10 numbers
asymptotically tight because AKTU 2018-19(Sem-2), Marks 07
not tight. constant c > 0, ifa
any positive
ogtn)) fn):for
=

that 0 <fn)< cgln) ¥nn


4-25 E (Sem-1 & 2) 4-26 E (Sem-1 & 2)
Solving Functiong
Programming for Problem
A (1] > A (2], Swap
A= 12, 5, 34, 3, 78, 98, 15,
101
Answer A [2] > A [3), swap
:

Importance of sorting easily and quickly. A [3] > A [41, No Swapping


A= 12, 5,3, 34, 78, 98, 15, 101
1 Sorting helps to find data applications. A [4] > A (51, No Swapping
in database location of an
2. Sorting plays a vital role uses time to find the A [5] > A [6), Swap
important as it less
3 Sorting is
element or data. So. A=12 5
334| 78 15 98 |101
4-21E, Unit-4.
Program :Refer Q. 4.23, Page Pass 3: Now
techniqueusing bubble
sort on the
sorting 2 4
Que 4.27. Implement
5 6.7
101, 15. A=12| 5 3 34 78
sequence:34, 78, 12, 5, 3, 98, 15| 98 101|
following AKTU 2021-22(Sem-1), Marks
10 Compare A[0] and A[1] as A [0] > A(1], Swap
2 3 4
56 7
A= 5 12| 3 3478 15 98
Answer 101|
:
Compare A[0] and A[2)
Given 56 0
0 1 2 3 4
5 6 7
10 15
A|34| 78| 12 5| 398 A=5s
A (2] >
1234 781598 101|
Compare A
(3], No Swapping
Pass l : Here n=8 A [3] > A14), No Swapping
[1] i.e., A[0]<A[1]
Computer A[0] and A A [41A I51, Swap
0.

Array will be 15
1 3 4
6
A=34, 78, 12, 5, 3, 98, 101, So,
31234| 1578 98101
A (2] so,
A
As, A[1] > l5]:> A [6], No Swapping,
101, 15 (6] > A (7],
A= 34, 78, 12, 5, 3, 98,
A
No Swapping
0 1 2
34 5
A[2] > A (3] so, Pass 67
15 4: NowA =
5
A= 34, 12, 5, 78,3, 98,101, 31234157898 101
Compare A [O]
A(3> A [4] so, >A [1],Swap
A=34, 12, 5,
3, 78, 98, 101, 15
01 4 5 6 7
As, A[4 >A [5] no swapping will be done A=3,512 34 1578|98 101|
A=34, 12, 5, 3, 78, 98, 101, 15 Compare A [0]> A [1],
No Swapping
Similarly, A[5] < A[6], No swapping A [1] > A (2), No Swapping
A [2] > A [3], No Swapping
98 15 |101
So,
A
=34| 12 5 378 A [3] > A [4), Swap
1 2
Pass 2: Now 4 5 6 7
6 A=
1 2 3 5
15 |101 Que 4.28.
512 15 3478|98 101
A=34| 12| 5 3 |78|98| What
is searching ?
linear Write a program to implement
Compare, A [0] > A [1], Swap search.
98, 15, 101
A= 12, 34, 5, 3, 78, AKTU 2021-22(Sem-1), Marks
10|
4-27 E (Sem-1 & 2)
Programming for Problem Solving

Answer 4-17E, Unit-4.


5
Searching: Refer Q. 4.16, Page
Program :
#nclude <stdio.h> UNIT
n, int val){

int linearSearch(int al int


),

II Going through array sequentially Pointers


for (int i= 0; i<n; i++)

if (a[i] = val)
returni+1; CONTENTS
return -1;
Part-I Pointers: Introduction.
5-2E to 5-6E
Part-2 Declaration
int main() ( .5-6E to 5-8E
11, 57, 41, 25, 14, 52); Part-3 Applications .
int al] = (70, 40, 30, Il given array 5-8E to 5-9E
Il value to bè séarched Part-4 Introduction to Dynamic
Memory Allocation 5-9E to 5-15E
int val=41; Il size of array (Malloc, Calloc, Realloc,
sizeof(a[O]); Free)
int n = sizeof(a) / S Store result
n, val);
int res = linearSearch(a, Part-5 String and String Functions.
printf("The elements of the
array are :"); 5-15E to 5-16E
Part-6 Use of Pointers in Self..
for (int i =0; i<n;i++) Referential Structure 5-17E to 5-18E
printf("%d", alil);
val); Part-7
printf("lnElement to be searched is:9%d", Notion of Linked List
No Implementation) s 5-18Eto 5-19E
if (res ==-1)
array");
printf("\nElement is not present in the Part-8File Handling File T/O Functions ...5-19E to 5-28E
else
array", res); Part 9
Standard C

printf("\nElementis present at %d position of Preprocessors..na5-28E to 5-31E


Part-10: Defining and Calling
return 0; Macros
Oand Command-Line Arguments 53IE to 595E

5-1 E (Sem-1 & 2)


Pointers
Programming for Problem
5-2E (Sem-1 & 2) Solving
e. Communicating 5-3E (Sem-1 & 2)
PART-1 | information about memory
which returns
the location of free memory as in the function malloc( )
Pointers: Introduction. by using a pointer.
Que 5.2. State
the features of pointers.
a given number Write a C program
using pointers. to sort
Questions-Answers
Answer
Answer Type Questions Features of pointers
Long Answer Type andMedium :
1. Pointers reduce
length and complexity
Use of pointers our
program of the program.
in increases the execution
on pointer. If we define an array
Que 5.1. Write a short note cannot pass in a function speed.
the address of that arraywith automatic storage class, we
4 A pointer contains garbage back to main( ).
Answer memory address of anothero. initialized. value (any unpredictable
1. Apointer variable that holds the
is a
5
Pointer variable can
value) until it is
be incremented or
(rather than data). memory address ofa vaiok, 6 Arithmetic operation decremented.
of data using the
The storage and retrieval arithmetic operation between pointer and constant
2. of using variable. between twopointers is permitted but
(i.e., a pointer) is faster than
that Program to sort a is not permitted.
: given number using
Initialization of pointer variables a
#include<stdio.h> pointers :
address of avariable to
1.
Initialization is a process of assigning the #include<conio.h>
#include<alloc.h>
pointer variable. assignment
Once a pointer variable has been
declared, we can use the void main).
2 variable.
operator to initialize the int n,p,i,j,temp;
Example: clrscr):
int total;: printf"\nHOW MANY NUMBER:");
declaration / scanf("%d, &n);
int *p; initialization */ p= (int ) nalloc(n
p÷&total; * declaration. That is, int ifpNULL) 2);
can also combine the nitialization with the
3 We
*p=&total reasons : printf(“\nMEMORYALLOCATION
of the following UNSUCCESSFUL;
Pointers are essential because by address when modification of
forma
exit();
arguments to functions
Passing on actual arguments. function to for(i = 0;i<n; i++)
arguments is to be reflected Conveniently trom one {
more
b Passing arrays and strings insteadd
another. poointerstothem print("\nENTERNUMBER
%d:" i+1):
more easily by moving scanf("od", p
Manipulating a arrays binary
tree, +i);
C

arrays themselves. lists and other data for(i =0;


moving the as linked i <n;itt)
structure, such references to
Creating complex data contain
d
where one data structure
must ebt forj = 0;j< n;j++)
structures.
Pointers
5-4 E (Sem-1 & 2) Programming for
Problem Solving
5-5 E (8em-1&2)
if(*(p + i) < *(p +j) Que 5.4. Explain the operations
on pointer
example. variables with
temp = *(p + i);
*(p+ i) = *(p +j);
Answer
Following are the
*(p +j) = temp; operations performed on
i. Assignment : pointer variables:
1, A pointer variable can
be assigned the address
of other variable.
printf("\nTHE SORTED NUMBERS ARE: \n): int *ptr, var;
:
Example
for(i = 0; i<n; it+) ptr= &var;
printf(“%d", *(p+i); 2
If two pointer variables are pointing
getch(); they can be assigned. to the object the same
of

data type,
Example:
? Hlow pointer vat
int *ptrl, *ptr2;
Que 5.3. What do you mean by poimters
on arithmetic wit% ptrl=ptr2;
are initialized ?Also, wvrite a note pointer 3 A pointer variable can
be assigned a NULL
example. value(NULL=0).
Example:
Answer int *ptr;
: Refer Q. 5.1, Page 5-2E, Unit5"
Pointer and its initialization ii.
ptr=Null
: Addition and subtraction :
Pointer arithmetic 1
An integer yalue can be added to
1. Incrementing a pointer : memory location and subtracted from apointer variable.
an which points to the
integer pointervariable Example
a. Let ptr be
an is 32-bit(4 bytes).
5000 and size of integer memory int *ptrx;
Now. when we incremenpoHaptr
(ptr++); it will point to
next integer location whuch ptrx =(ptrx
b. willj
location 5004 becausé itcurrent
+2);,
4 bytesnext to the locatio. Ptrx= (ptrx- 1),
is 2. One pointer variable can be
subtracted from another pointer variable,
Decrementing a pointer: number of both are pointing to the elements if
2 decrease its value by the of same array.
the
Decrementing a will
pointer,
Example:
bytes ofits data type. static int x[4] = (10, 20, 30, 40);
-
b. Hence, after ptr int *ptr1, *ptr2, *ptr3, *ptr4;
ptr will point to 4996. ptr-(sizeof(pointer_data_type). ptrl = &x[1];
to
ptr-; is equivalent : two
apartthetwo
kptr2=&x(31;
Subtracting pointers indicates"How. between
ptr3 = ptr2-ptrl;
3 pointers elements
Thedifference between two number of e Comparison: Iftwo pointer variables are pointing to
It gives the total pointer
the objects of the
pointers are". an integer
pointer
ptr same data type,
then they can be compared with one another.
If
pointers. 4 bytes. Example:
Let size of integer is
integer
andofptr2-ptrlis2
b. For example, memory location 10000result
points at
ptrl'
at memory
location 10008, the:
points
Pofnters
Programming for Problem
5-6E (Sem-1 & 2) Solving
*ptr2; main() 5-7E (Sem-1 & 2)
int *ptr1, (ptrl == ptr2)
then,
(ptrl!= ptr2) char a[201, *ptr;
(ptrl<ptr2)
int i, len, t, back;
(ptrl> ptr2) printf("Enter the string:");
performed. getsla);
etc., can be
PART-2 len = strlen(a);
Declaration.
-
back = len 1;
printf("The entered stringis:");
puts(a);
Questions-Answers
if(len%2 != 0)
9uesti
Medium Answer Type
Tong Answer 1ype and for(i = 0; i< (len- 1)
/2;i++)

pointers t= ali);
Que 5.5. How to declare ali] = a[backl;
a[back]=t;
Answer
declaration of a pointer variable takes the following form: back-
1.
The
data_type pt_name; variable. pt name.
compiler three things about the variahle
This tells the pt name is apöinter if(den%20)
asterisk (*) tells that the variable
The
a. memory location.
pt_name needs a _type. for(i = 0; i<len/2; itf)
b. of type data

pt_name points to a variable


C.
pointer */
int *p; integer use styles: t=alil;
Programmers the following alil = alback]:
2.
a[back] =t
int*p;/ style 1*/
2 */ back--;
int *p; /* style
3 */
int * p;/ style reversea string through
pointer.

Write a program in Cto U1


printf(The reverse
2017-18(Sem-2),Marks
of a
Que 5.6. string is:);
AKTU puts(a);
getch();
return 0;
)
Answer
#include<stdio.h>
#include<conio.h>
#include<string.h>
Pointer8 Programming for Problem Solving
5-9 E (Sem-1 & 2)
(Sem-1 & 2)
5-8 E in C. Write a program
theimportanceofpointers by user using
QuestionsAnswers
Explain entered
Que 5.7. values of two numbers Long AnswerType and Medium Answer Type Questions
swap the
in to reference method.
AKTU 2018-19(Sem-2), Marks
C

function call by
Que 5.8. Write down the applications of pointers in C.
5-2E, Unit-A
Answer : Refer Q. 5.1, Page
Importance ofpointers Answer
Program : Applications of pointers in C:
#include <stdio.h> 1 To pass arguments by reference. Passing by reference serves two
*): purposes:
swap (int *, int
i. To modify variable of function in other. Example: to swap two
main() { variables;
int a, b; a & b: "):
printf(“\nEnter value of For efficiency purpose. Example: passing large structure without
&b); reference would create a copy of the structure (hence wastage of
scanf("%d %d", &a,
Swapping:\n"); space).
printf(“\nBefore %d\n", a, b): For accessing array elements. Compiler internally uses pointers to access
2
printf(“\na = %d\n\nb= array elements.
swap(&a, &b); 3 To return multiple values. Exanmple: returning square and square root
Swapping: \n"); of numbers.
printf"\nAfter a, b);
printf(«\na =
%d\n\nb= %d",
PART-4
getch); ) (
swap (int *x, int
*y) Introduction to Dynamic Memory Allocation
Malloc, Calloc, Realloc, Free).
int temp;
temp = *x;
*x=*y; uestionsAnswers
*y= temp; Long Answer Type and Medium Answer Type Questions

Output: a & b: 10 20
Enter value of ue 5.9. Write a short note on the dynamic
memory allocation.
Before Swapping:
OR
proper example.
a 10 Dxplain dynamic memory allocation concept with
10
b= 20 AKTU2020-21(Sem-1), Marks
After Swapping:
Answer
a 20 ofallocating memoryat runtme.
ynamic memory allocation isaprocess
be 10 PART-3
Applications.
Pointera Programming for Problem Solving
5-11E (Sem-1 &2)
& 2)
5-10 E (Sem-1 that can be used for
management functionsexecution. Answer
memnory program
There are four memory during The conceptual view of storage of a C program
allocating and freeing 5.9. 1.
2
1
in memory is shown in
allocation functions
Table Fig. 5.11.1.
in
They are listed 5.9.1. Memory
3. Table
Task Local variables Stack
Function size ofbytes and returnssa pointer Free memory
Allocates request allocated space. Heap
malloc() to the first byte of the Global variables
an array of elements initializes program instructions Permanent
Allocates space for
C

returns pointer tothe


a
storage area
calloc ) zero and then
them to Fig. 5.111,
memory. storage of a Cprogram.
allocated space. The program instructions,
Frces previously 2 global and static variables are stored a
region known as permanent storage area in
freel ) allocated space.
Modifiestthesize of previously stored in another area called stack. and the locál variables are
realloc() The free memory region known as
memory allocation 3 heap is located between these two
are the various types
of
regions and is available for dynamic allocation
What during execution of the
Que 5.10. demerit. program.
merits and
technigues ? Give its The size of the heap keeps changing when program
is executed due to
creation and death of variables that are local to functions
and biocks.
Answer memory allocation techniques 5. Therefore, it is possible to encounter memory "overflow"
during dynamic
types of : Static memory allocation refers tothe allocation process.
There are twomemory allocation
Static memory at compile time beforé the associated When memory, allocation functions fail to locate
enough memory
process of allocating
1

requested, they return a null pointer.


program is executed. of modularizing
&.t.
Que 5.12. Define the concept of pointer.
Merits memory allocation has the advantage Also, define the dynamic
:

data mus ke

Static where these memory allocation and various functions for dynamic memory
design in the situation
within a program program.
a.
runtime of the allocation with suitable example.
retained through the
sane
scope ensuring that the
is global in its consistency. FAKTU 2017-18(Sem-1), Marks 07
A defined value throughout a run for
immutable value is used memory needed is not known at compl:
b.
Answer
amount of
Demerits : If the to make a guess. 5-9E, Unit-5. Pointer : Refer Q. 5.1, Page 5-2E Unit-5.
tlhen one has : Refer Q. 5.9, Page This helps in Dynamic memory allocation : Refer Q. 5.9, Page 5-9E, Unit-5.
time memnory allocation on an as needed basis.
Dynamic memory allocation. Various memory management functions used for memory allocation
is allocated to static
2
Merits: Memoryinefficiencies inherent
are:
1, malloc( ):
removing the memory allocatod a. The malloc( ) function is used to allocate heap storage.
than happens in the e static
Demerits: memoryallocation is slower b. Syntax of malloc):
Dynamic memory allocation
ptr= (cast-type*) malloc(byte-size)
a. because dynamic after
use. 1hey
This is carefullydeleted
Here, ptr is pointer of cast-type.
area. segmen.
memory needs to be memory 2 calloc():
witha
Dynamic non-contiguous area of ASSociated
a "The calloc() function is used to allocate the continuous memory or
b. process
created in element by element basis.
memory. allocation
Que 5.11. Explain
Pointers Programming for Problem
5-12
E
(Sem-l& 2) Solving
5-13 E (Sem-1&2)
Using free( ) function:
Syntax of calloc(0:
b. element-size); t#include<stdio.h>
ptr= (cast-type*)calloc(n, memory for an
contiguous space in tinclude<stdlib.h>
This statement will allocate #define NULL0
array of n elements.
main()
realloc(): or decrease the size
off
3 used to increase
a. The realloc() function is char *buffer;
memory.
block of heap $ Allocating memory */
b Syntax of realloc(): if(buffer = (char *)malloc(10)) ==
newsize); NULL)
ptr =realloc(ptr,
reallocated with size of newsize.
Here, ptr is printf("malloc failed. \n");
within the
to free a portion of storage
free( ): exit(1);
The free( ) function is used alloc( ), malloc( ), calloc() or realloc )
previously allocated by
heap printf("Buffer of size %d
created \n",msize(buffer);
b. Syntax of free( ): strepy(buffer, "HYDERABAD");
free(ptr); printf(“\nBuffer contains:%s
space allocated in the memory pointed
b. \n", buffer);
This statement frees the Reallocation */
ptr. if((buffer = (char *)realloc(buffer,
15)) == NULL)
Example :
Using realloc() and malloc( ) function: printf(“Reallocation failed. \n):
exit(1);
#include <stdio.h>
#include <stdlib.h>
)
printf("|nBuffer size modified. \n");
int main( printf("\nBuffer still contains: %s \n".buffer);
strcpy(buffer, "SECUNDERABAD");
int *ptr, i, nl, n2; printf(“\nBuffer now contains: %s \n",buffer);
");
printf"Enter size ofarray: * Freeing memory */
scanf("%d", &nl); free(buffer);
* sizeof(int));
ptr = (int*) malloc(n1
allocated memory: ");
printf("Address ofpreviously ue 5.13.
What is dynamic memory allocation ? Explain
the
for(i = 0; i<nl; ++i) calloc0, malloc),realloc) and free) functions
lifetime of a variable, which is in detail. What is
printf("%ou\t",ptr +i); created dynamically?
array: ");
printf(“\nEnter new size of AKTU2018-19(Sem-1), Marks 05|
scanf("%d), &n2);
Answer
ptr =realloc(ptr, n2); Dynamic
memory allocation : Refer
Calloc0, Q. 5.9, Page 5-9E, Unit-5.
for(i = 0; i< n2; ++i) Lifetime malloc), realloc), free) : Refer Q. 5.12, Page 5-11E, Unit-5.
printf("ou\t", ptr +i); existence of variable: Alllvariables have a finite lifetime. They come into
from
return 0; the point at which you define them and at some point they
Pointers Programming for Problem
&2) Solving
5-14 (Sem-1
E
a particule.
program ends. How long which
5-15 E (Sem-1 &2)
int sum:
at the latest, when your
storage duration. Variables for you I/to store sum of all elements
are destroyed by its storage duration: they exist. print("Enter limit of the array:
is determincd dynamic "):
variable lasts have you release their memory to scanf("%d", &limit);
memory at runtime create them until
allocate which you ldeclare memory dynamically
point at
from the ptr= (int*)malloc(limit * sizeof(int)):
destroy them. memory allocation. Differentiato
Que 5.14.
Define dynamic proper examplc. I/read array elements
() with for (i = 0; i < limit; i++)
malloc () and calloc {

between AKTU 2021-22(Sem-1 Marks 10|


printf("Enter element %d:", i+ 1):
scanf("%d", (ptr + i));
E
5-9E, Unit.
Answer memnory allocation : Refer 5.9, Page Q

Dynamic llprint array elements


Differcnce: calloc) printf(“\nEntered array elements
are:\n");
S.No.malloc() creates a calloc() function assigns multiple for (i = 0; i< limit; it+) {

1
malloc) functionmemory of a blocks of memory to a single printf("%d\n", *(ptr + i));
single block of variable.
specific size.
of arguments in The number of arguments in llcalculate sum of all elements
2
The number calloc() is 2. Sum = 0: llassign 0 to replace garbage
malloc) is 1. for (i = 0; i< limit; i++) value
calloc() is slower. {

malloc() is faster. efficiency. sum += *(ptr +i);


3.
time calloc() has low time
4
malloc() has high
efficiency. by printf("Sum of array elements is: %d \n",
The memory block allocated sum);
memory block allocated calloc() is initialized by
zero. free(ptr); I/ree dynamically allocated memory
The
5.
by malloc() has a garbage return 0:
value. contiguous
memory calloc() indicates
malloc() indicates allocation.
6.
allocation. memory with dynamie PART-5
the
a program to allocate user and find String and String Functions.
Que 5.15.| Write concept. Take the input from the Marks10
2021-22(Sem-2),
memory allocation |AKTU
elements. Questions-Answers
the sum of all
Long Answer Type and Medium Answer Type Questions
Answer
#include <stdio.h>
#include <stdlib.h> Que 5.16.
Describe string.
int main() nointer
Ildeclaration of integer
int* ptr;
array limit
/to store
IMoop counter
int limit:
int i:
Pointers
2)
Programming for Problem
5-16 E (Sem-1 & Solving
5-17 E (Sem-1 & 2)

Answer array of characters


defined as the one-dimensional PART-6
The string can be
se ofPointers in
terminated byanull (\0).
1 Self Referential Structure.
used to manipulate text such as
array or the string is
The character
2 sentences. Questiong-Answers
word or array occupies one byte
of memory, and the
last
Each character in the be 0. Long Answer Type
3
character must always and Medium AnswerType
important in a string since it isthe Questions
character (\0) is ends.
The termination string
4
only way to
identify where the
s[10]. the character s[10] is implicitly Oue 5.18. Explain
When we define
a
string as char
memory. self-referential structure
5. null in the with its type.
initialized witla the is as simple as declaring a one-
: Declaring string
a
Answer
Declaration of strings string:
a
syntax for declaring
dimensional array. The basic 1
Self-referential structures:
str_name[size]; Self-referential structures are
char any name given to the string variable :and pointers which point to those strüctures
that have one or more
the same type of structure,
In the above
syntax str_name is of the string, i.e., the number of characters Structures pointing to the same as their member.
define the length 2

type of structures are self-referential


size is used to nature. in
strings will store. ? Example:
are different string functions struct node
Que 5.17. What
{

int datal;
char data2;
Answer struct node link
are:
Different string functions Description main).
Function oint
S.No. returns the length of string
strlen(string_name) structnode ob;
1
name. return 0;
of source
copies the contentsstring.
strcpy(destination, source). string to destination 3 Inthe above example link is a pointer to a structure of type
2. Hence, the structure 'node is 'node'.
string with a self-referential structure
concats or joins firstresult of the the referencing pointer. with link' as
second
strcat(first string, The
second string. first string. Types of self-referential structures are as
Self-referential structure with single follows:
3
1.
string) string is stored in with link:
string These structures can have only one self-pointer as
Compares the first strings are The following example will show us how to connect their
member.
stremp(first_string, second secondstring. If both the objects of a
self-referential structure with the single link and access
returns 0. corresponding data members.
the
string) same, it
reverse string.
C. The connection formed is shown in the following
returns figure :

characters 1"
strrev(string) 10
5. returns string 20 30 20 X

strlwr(string) lowercase. characters 2. obl


Self-referential ob2
6. string structure with multiple links:
returns
uppercase.
strupr(string)
7.
Pointers Programming
5-18 E (Sem-1 & 2) for Problem Solving
can have more than one self. Singly linked
These structures with multiple links list :In singly linked 5-19 E (Sem-1
& 2)
single link which
pointer. can be easily constructed using following singly attaches it to list, each node
b. Many complicated data structures linked the next node
list representation :
contains data and
in the list. Consider a

structures. at o
these than one node mo
can easily connect to more structure the
C. Such structures shows one such with
time. The following example null
than one links. fiomwe. b. Double linked list: Fig. 5.19.2.
can be understood using the following In double
The connections made linked list, each
d.
10! 20!
ob2
30x
obl
the previous node
Singly connected
node contains
and one to the
lists cannot
data andtwo
next node. links, one to
obl with the same ease as be traversed
forward traversal. in backward manner,
PART-7| # However, double
linked list can
Implementation). with ease as shown be traversed forward
(DNo in Fig. 5.19.3. and backward
Notation ofLinked List
10 20
30
null
Questions-Answers Fig. 5.19.3.
Circular linked
Questiong contain the NULL
list : Ina circular linked
list,the last node does not
Medium Answer Type pointer.
node as shown in Fig. 5.19.4.Instead it contains the pointer of the
Long Answer Type and frst
Start

linked list in brief.


Que 5.19.|Explain
allthe Fig. 5.19.4.
Answer same data type, andmemory
linked list is a collection of records of the which holds a
A variable
by pointers (a
1

records are connected pointing to next PART-8


address).
has a field that is a pointer list is assigned File Hundling
Each record in a linked
list record ofthe File I10 Functions.
2
pointer field in the last
record in the list. The
in the list.
the null value. used to point to the first recordshown in Fig. 5.19.1 Questions-Answers
variable is
3 A pointer representation ofa linked list is LongAnswer Type and Medium
4. The diagrammatic Next
Info Answer Type Questions
Info
Info Next
Fig:5.19, ofelements and allocate memory
necessary. Que 5.20.
Define file. What are
necessary to know the number as and when
can be allocated in the structure are
its types?
Itis not
5. beforehand. Memory data
structure and the useful structure ana neu Answer
for them
case the size of the array is nota d Aile is a collection ofrelated records such as the records of employees
6
In then the without
constantly changing lefficiently
handlede
in a company.
2
linked list is used. deletions can
be are Each record
will be a collection ofrelated data items called fields. Each
insertions and which
held consists of group
7 In a linked list, list. linked lists of characters.
restructure the types of
having to various
: There are
Types of linked list
following:
Pointers Programming for Problem
5-20 (Sem-1&2)
E
G
Solving
of data
associated with the processing 5-21 E (Sem-1
3. The common operations Answer & 2)
are: Various functions
Reading from a file (input) 1. getc() :
of files are :
Writing to a file (output) a. getc() function
at the end)
Appending to a file (writing
output I/O)
is used to read a single
and returns EOF(End-of-file) character
C.
a file (input or condition at froma givenfile
d. Updating
OCCurs.
in which data is stored., iles are primarily The general format the end or if an error
Depending upon the format: b.
of the getc) function
4. types where fptr is a
categorized into two file pointer is : ch= getc (fptr);
receives the character. of the file, and
a. Text file : information like alphabets, nurmbers, :
ch is a variable
that
text file stores textual actuality, the ASCII codee of textul
A 2 fgetc)
1

symbols, etc. In a.
fgetc() is used to
special text files. read a
characters is stored in the b The general format of single character froma given file.
device in the binary format,
storage where fptr is a file the
fgetc() is : ch =fgete
Since data is stored inaare first converted in the binary form pointer of the file,
(fptr);
2, contents receives the character. and ch is a variable
the text file the storage device that
before actually being stored in sets such ae. putc):
character
3.
A text file can store different (A to Z)
a. The putc() function is used
to write a single
case English alphabets The general format of the character into a file.
i. Upper to z) putc()function is : pute
Lower case English alphabets (a where ch is the character
to be written and
(ch, fptr);
i 1, 3, 5, etc.) a file to receive a character. fptr is a file pointer to
Numeric characters (like :
:, etc.) 4 fpute)
Punctuation characters (like ;,,?, a. The fputc() function is used to write a
iv. $, %, etc.)
V.
Special characters (like given file and advance the associated single character on to a
file position indicator.
: b The general syntax of the fputc() is :
fputc (ch, fptr);
b. Binary file information in the binary form, ie. in
where ch is a character to be
A binary file stores the stored in the memory. written and fptr is a file pointer to
the file to receive the character.
1. as is
the same format it the need of
data
fputs() :
binary file eliminates
5.

Thus, the use of for storage purpose. a.


binary format The fputs() is used to write a given string to a given file.
2
conversion from text to the data
file is that form. normally used to copy strings from one file to another. It is
drawbackS of binaryunderstandable
3. One of the main file is not in human b. Thesgeneral format of the fputs() function is as follows : fputs
stored in a binary operations such
as read, wite (sptr, fptr)
supports binary file where sptris a pointer to the string to be written
and fptr is a file
4 C language pointer to the file.
and append. 6. fgets) :
functions of file.
various
a
fgets() function reads characters until it reaches a new line, an
Explain
Que 5.21.| OR operations :
end-of-file, or the maximum number of characters specified.
b
in file
following functionsii. putw() 7.
The format of fgets() function is : fgets (sptr, n, fptr);
fread() :
Explain the fprintf()
2017-18(Sem-2),
Marks
a.
iv. The fread() function is used to read a block of binary data from a
i. getw() given file.
iii. fscanf() AKTU b.
The general format of the fread) function is : fread(ptr, size,
nitems, fptr);
Pointer8
Programming for
2) Problem Solving
5-22 E (Sem-1&
5-23 E (Sem-1 & 2)
fwrite(): write clements from the arTay to
The fwrite()
function is used to puts(“File not
found.");
a. exit(0);
the stream. format of. fwrite() is: fwrite(ptr, size,: nitems, fptr)
The general if(ft = fopen("c:\ltc\\bin
b
fscanf() : data from a specified laaaa.txtw") ==NULL)
9. used to read formatted
a.
fscanf() function is puts("Target file
cannot be created.");,
fclose(fs);
file. fscanf() function is : fscanf(fptr, "control
general syntax
of
The exit(0);
b
string", &list);
while((ch = getc(fs))
10. fprintf() : used to write formatted
dataa
into a given file. != EOF)
fprintf() function is
of fprintf() function is: fprintf(fptr, "control putc(ch, ft);
form
b The general
string", list);
to write formatted data puts(“File copied successfully.");
where fptr is a file pointer fclose(fs);
11. getw()
:

used to read an integer value from given file,


a fclose(ft);
getw()function is is :getw(fptr); getch( );
The general format of getw)
a
välne
a to receive an integer return 0;
where fptr is a pointer to file
b.

: an integer quantity to the


on
12. putw)
putw) function is used to write Oue 5.23.What are the various types
a.
specified file. of files that can be created
function is : putw(w, fptr); C language? Also, in
The general format of putw) fptr is a file pointer used with proper give different modes in which these
syntax. Write a program files can be
b.
where w is an integer value to be written and some more text
át the end of an existed textinfile
Clanguage to append
to a given file. program for copying OR
handling and write a
Whatare different
fileopening mnodes in C?
Que 5.22. | Explain file the contentsof one file
into other file.
Write a program to copy
one file into another file. 2020-21(Sem-1), Marks 10
the content of FAKTU AKTU2017-18(Sem-1),
Marks 07
Explain thedifferent OR
type of modes and I/0 function
of storing data in te in file handling.
Answer to the method gener
handling : File handling refers
or input that might have been
or a
textfile for
AKTU 2020-21(Sem-1), Marks
10|
File an output a binary file
progranm in the form of file, i.e.,
program in datavery program.
a
a C
Discuss about the file OR
while running that handling concept and write
and reference in
COpy the content a
of one program to
future analysis file to another and print the count of these
#include<stdio.h> coping elements.
#include<dos.h> AKTU 2021-22(Sem-2), Marks 10
nswer
main( ) Types of
file : Refer Q. 5.21,
Page 5-20E,
FLE *fs, *ft; bes eixcierr ==NULL)
Unit-5.

char ch;s llaa.cpp,r+")


clrscr( );fopen("c:Iltc\\ bina
if(fs=
agibes
Pointers Programming for Problem
Solving
& 2)
5-24 E (Sem-1 gets(fname2); 5-25 E (Sem-1 &2)
:
file fpl = fopen(fname1, "r");
Modes of accessing Meaning fp2 = fopen(fname2, "a");
S.No. Mode only (for input)
To open a file for reading beginning.
if(fp1 ==
NÚLL || fp2 = NULL)
1. Reading occurs from the
writing only (for output). printf("unable to open");
To open file for
a

already exists, it will


2. If the file exit(0);
overwritten.
To opena
file for appending (for output). do
at the end-of-file
"a" We can write only {
3. move
position. Even ifwe explicitly the fle
ch = fgetc(fp1);
indicator, writing shall 0ccur at the
end-of-file. fputc(ch, fp2);
To open an
existing file for reading and
r+ writing (WO). The file position indicatoris while(ch != EOF);
4.
initially set to the beginning of the fle fcloseall0;
a new file for reading and writing
To open
(T/O), If the file already exists, its contente
5.
are destroyed. Ifthe file does not exist, a Oe B24. Suppose a file contains
student records with each record
new file is created. nntaiming name and age of a
appending Alese records and display student. Write a C program to read
To open a file for reading and them in sorted order by name.
and create the file ifit does not exist
6 "a+" (/O) but
We can read data anywhere in the fle, Answer
we can write data only at the end-of-fle #include <stdio.h>
reading. struct record
N
Open binary file for
7.rb" Create binary file for writing. char namne[101;
int age;
Append to a binary file.
"ab" read/write.
Open binary file for
9
void main(o
10."Tb+" or "r+b" Create binary file for
read/write.

11.
wb+" or "w+b" FILE *fp, *ft;
int i,f=1;
: struct record a[500]:
Program clrscr);
#include<stdio.h>
fp= fopen(“c:\ \ctxt\ \record.txt" ):eo e
#include<conio.h> if(fp == NULL)
void main()
puts(“Cannot open
exit():
file);
FILE *fp1,*fp2; fnamne2[20];
fnamel[20], for(i = 0;
char ch, i<500;i++)
source file name");
printf\n enter
gets(fnamel); name");
source file
printf\n enter
Pointers Programming for Problem Solving
& 2) 5-27 E (Sem-1 & 2)
5-26 E (Sem-1 fptr = fopen("text.txt", "w");
if(fptr == NULL)
if(f == 1) == EOF))
ali].name, &ali].age) printf(“File cannot be
if(fscanf(fp, "%s%d", getch();
created \a");
f=0; exit(0);
)

iflf == 0) printf(“Enter some text


ali].name[0] = \0; while((ch = and press enter key:\n");
getche())!=\r)
{

funcsorta,4); fputc(ch, fptr);


ali].name[0] != \0; i++) ali].name, a[i].age);
for(i = 0; Age is %d",alphabetical order");
printf("\nName is %s.according to fclose(fptr);
printf"\nFile sorted\record2.txt",w"); fptr= fopen(text.txt","r");
fopen("c:\ \ctxt\ printf(“\nContents of the file is:"):
ft= ali].name[0] != 0; it++) alil.age); while((ch = fgetc(fptr)) != EOF)
for(i = 0; ai).name,
fprintf(ft, "%s %d \n",
fclose(fp); count++;
fclose(ft); printf("%c", ch);
\record.txt"); \record.txt"):
remove("c:\ \ctxt\ \record2.txt","c:\\ctxt\
}

rename("c:\ \ctxtl fclose(fptr);


printf(“\nThe number of characters present
C.
Write a program in in file is: %d",count):
operations in getch();
Define various file in file,
Que 5.25.| characters
of
C to count and
print the number Marks 07 Oue 6.26. Explain different file opening modes. Write a program
AKTU 2018-19(Sem-2),
to read content of any file and display the numberof lines and
performed words in that file. AKTU 2021-22(Sem-1), Marks 10
Answer C:Different operations that can be
Various fileoperations in Ansu
wer
or "wor w+)
on a file are
(fopen with attributes as "a" or "a+" File opening modes: Refer Q5.23, Page 5-23E,Unit-5.
Creation ofa new file
an éxisting file (fopen) Program :
2 Opening an #include <stdlib.h>
fgets)
Reading from file (fscanfor
(fprintfor fputs) int main()(
Writing to a file rewind)
location in file (fseek, FILE * file:
4
a
5. Moving to a specific char path[100];
Closing a file (fclose)
6.
number of charactersina file: char ch;
Program to count the int characters, words, lines;
#include<stdio.h>
file = fopen("counting.txt","w");
#include<conio.h>
void main() printf(“enter the text.press cntrl
Z:;
-
while((ch getchar())!=
EOF)\
char ch; pute(ch,file);
int count = 0;
FILE *fptr;
clrscr);
nch

Pointers Programming for Problem Solving


E (Sem-1 &2) 5-29 E (Sem-1 &2)
5-28
fclose(file); OR
path: "); Explain the syntax and use of
printf(“Enter source file examples : the following directíves with
scanf("%s", path); i. #ifdef ii. #undef
"r"; iii. #pragma iv. #include
file = fopen(path,
== NULL){ |AKTU 2017-18(Sem-2), Marks 07
if (file
printf"Unable to open file."); Answer
exit(EXIT_FAILURE); Preprocessor directives are lines included a program
1.
in that begins with
the character #.
= lines = 0: 2. Preprocessor directives follow special syntax rules
characters = words that are different
EOFX from the normal C syntax,
= fgetc(file)) != are
while ((ch They invoked by the compiler to process some programs
compilation. before
characters++;
ch ==\0) These directives can be divided into three categories:
if (ch =="|| 4
a Macro substitution directives
lines++; ch ==\0)
ch == (\t || ch=|| b File inclusion directives
if (ch =="|| C. Compiler control directives
words++; A set of commonly used preprocessor
5 directives and their functions is
given in Table 5.28.1.
if (characters > 0) Table 5.27.1 Preprocessor Directives
words+; Directive Function
lines++; #define Defines a macro substitution
#undef Undefines a macro
printf(“"; include Specifies the files to be included
= %d", words);
printf("Total words #ifdef Test for a macro definition
#endif Specifies the end of #$if
printf"Total lines =%d", ines): #ifndef Test whether a macro is not defined
fclose(file); Test a compile time condition
return 0; #else Specifies alternatives when #if test fails
#elif Provides alternative test facility
#pragma Specifies certain instructions
PART-9 #error Stops compilation when an error occurs
Standard C PreprocessorS. #ifdefdirective is :
1. #ifdef: The syntax of

#ifdef macro_definition
Questions-Answers Use : This directive checks whether the identifier is currently defined.
ldentifiers can be defined bya #define directive or the command line.
Questions on
Medium Answer 1ype For example :
Long Answer Type and
#include <stdio.h>
three of
any #define RAJU 100
Explain
preprocessor directive ? int main)
Que 5.27.| What are
them.
Pointers Programming for Problem Solving
2) 5-31 E (Sem-1 & 2)
5 30E (Sem-1 & For example :
#include<stdio.h>
fleln2). #define PI 3.1415
#ifdef RAJU will be added in " \“this C #define circleArea(r) (PI*r*r)
printf"RAJUis defined. So, this line
int main()
#else
defined \n");
printf"RAJU is not int radius;
#endif float area;
return 0; printf("Enter the radius:"):
directive is: scanf("%od", &radius);
syntax of #undef
#undef: The area = circleArea(radius):
2 #undef token or preprocessor: macro
a constant printf(“Area = %.2f", area);
directive undefines #undef i used tO SCope a
Use:The#undef using #define. Usually, return 0;
defined previously very limited region.
preprocessor constant into a
:
For example oe528. Why are preprocessorrequired
#define E2.71828 ? Explain any two
e _squared =E*E: preprocessor directives.
int AKTU 2021-22(Sem-1),
#undef E : Marks 10|
#pragma is
3.
#pragma: The syntax of
compiler specific
extension Answer
#pragma preprocessor Reguirement of preprocessor :The preprocessor
access compiler-specific provides
pragma directive isused to #pragma once directive, the inclusion of header files, macro the ability for
expansions, conditional compilation,
Use:The thè
common use of #pragma only a single time,
no and line control. It provides preprocessor
extensions. A
compiler to include a header file preprocess the source code directives that tell the compiler to
which asks the imported. before compiling.
has been Preprocessor directives:Refer Q.5.27, Page
matter how many times it 5-28E, Unit-5.
Forexample:
#pragma once PART-10
Ilheader file code an include guard Defining and Calling Macros and
#pragma once is equivalent to ommand-Line Arguments.
using times.
In this example, file frombeing processed multiple
that prevents the Ouestiong Ansver
#ifndef_FILE_NAME_H
#define_FILE_NAME_H Long Answer Type andMediumn
Answer Type Questions
f* code *#ifndef_FILE_NAME _H
#endif// ue 529.
#includedirective is: What is macro 2 How
#include:The syntax
of
4. name> uacro act as a is it substituted ? Also explain
#include <header preprocessor topaste tne variable and macro act as a function
the example. with the help of
directive instructsGenerally, it is not placedteinthe
necessary to
Use:The include current file. AKTU 2017-18(Sem 1), Marks 07
file into the are
of thegiven header files if they
preprocessor where to look for Explain macros. OR
directory.
Current directory
or a standard system AKTU 2018-19(Sem-2), Marks 07|
Pointers Programming for Problem Solving
5-33 E (Sem-1 & 2)
& 2) This sequence
5-32 E (Sem-1 5.
macro body of tokens replaces the identifier VA ARGS_in
wherever it appears. the
symbol forintf ("%s:%d: ", input_file, Thus, we have this expansion:
by the
Answer directive which is denoted lineno)
»fprintf (stderr, "%s:%d: ", input_file,
preprocessor #def lineno)
Macro is a constant value using 6. The variable argument is completely
1,
"#define". identifier having inserted into the macro expansion, macro-expanded before
an # it is
just like an ordinary argument.
allows defining program. The symbol Macro as a function :
2. C beginning of a Callowed at the end 1. To define a function-like macro, we
directive. placed at the semicolon is but we put a pair of parenthesis use the samne #define' directive,
This directive is column and no immediately after the macro name.
3.
occurs in the first For example :
example, #define lang_init) c_init()
4. For
PI 3.14
# define MAXIMUM 100 A function-like macro
lang_init() c_init()
a program is 2 is only expanded ifits name appears
# define
substitution : process where
an identifier in tokens of parenthesis after it. we with a pair
or more If write just the name, it is left alone.
Macro composed of one direction of can be useful when
a
Macro
substitution is
predefined string task under the
#e 3. is
name. and we wish t0 use
we have a function
and a macro of the same
1.
replaced by a
preprocessor accomplish this the function sometimes.
definition (or simply: a macro) extern void foo(void);
2 The as a macr #define foo) /* optimized inline version */
statement. usually known
statement, form :
3. This following general identifier string then the foo);
takes the #define program at the beginning, soy
the in the funcptr = foo;
statement is included in occurrence of the identifier Tore the call to foo()will use the macro,
4.
Ifthis replaces every common but the function pointer will
preprocessor get the address of the real function.
substitution. T'he most
code by the string. forms of macro 4. Tf
the macro were to be expanded, it would cause a syntax error.
different Application of macros
There are
:
5. The use a macro
forms are macro substitution. of in place of a function eliminates the time delays
:
1
Simple substitution. associated with function calls.
Augmented macro If a program contains many reported function calls, the time savings
macroO substitution.
2
b
Nested resulting from the use of macros can become significant.
C.
Types of macros :

Program : 3.14 1. Object-like macros : The object-like macros is an identifier which is


# define PI replaced by the value. It is widely used to represent the constant
#include <stdio.h> value.
For example : #define mun 2.00. (Here mun is
main() will be replaced by value),
the macro name which
2, Function-like macros :
float r = 5.25; The function macros looks like function call.
For example : #define MIN(a, b) ((a) < (b) ?
float area; (a): (b)).
area = PFr*r; areal) Que55.30.| Explain command-line
printf("\nArea ofa circle =%f, argument with example. Give its
properties.
Output a: arguments. Explain OR
circle = 86.546249 command line arguments C
Area of ofa in with the help of example.
:
Macro as a variabledeclared to accept a variable number
macro can be
AKTU2018-19(Sem-1), Marks 10
1
A
macro is, _ARGS_J
syntax for defining thefprintf (stderr, VA afterthe Discuss
2 The
#define eprintf,..) variadic. argumentlist Commas,
about the command OR
line argument with example.
called
This kind ofmacro is tokens in itsincluding any
macro invoked, allthe
is none). AKTU 2021-22(Sem-2), Marks 10
4. When the argument (this macro has
last named argument.
become the variable
Pointers Programming for Problen
Solving
5- 34E (Sem-l
& 2) 5-35 E
(Sem-1 &2)
i. Macro expansion
ii. File inclusion
program whex AKTU 2018-19(Sem-1),
Answer supplied to the
Command line
argument is a parameter Answer
Marks10|
1. concept in Cprogramming.
it is invoked. argument is an important our program from outeid i. Macro expansion :
Command line to control 1. Macro expansion or macro
2. when we need main() metho
3. It is mostly used arguments are o the
: identifier in a program substitution is a process
4.
line
Command command line ar is
...
as follows of one or more tokens.is replaced by a predefined string where an
composed
Syntax of { /) 2. It takes the following general
5. arg, char *argv) form:
int main(int #define identifier
macro_string
or main(int argc, char $*argv) {... */) command lino 3. Consider an example program code
int arguments on the used the #define directive. given below. The program
argc counts the number of pointers oftype char which points
Here
a pointer
array wvhich holds include <stdio.h>
is
argvlarguments program. #include <stdlib.h>
passed to the #define LENGTH 10
to the
For example: #define BREADTH 20
#include<stdio.h>
#include<conio.h>
int main()
arge, char *argvl)
int main(int int area_rectangle =0;

ries
area_rectangle =LENGTH* BREADTH:
int i; printf("Area of Rectangle =
%d\n,area_rectangle);
ifl argc >=2) system(PAUSE");
suppliedare: \n"; return 0;
printf("The arguments
for(i = 1; i<arge; it+) The LENGTHand BREADTH are
4

called the macro templates.


The values 10 and 20 are called macro
5.
printf("%s\t, argv[i); expansions.
6.When the program run and if
C preprocessor sees an instance
ofa macro within the programthe
code,
It replaces the macro template withitthewill do the macro expansion.
value of macro expansion.
else ii.File inclusion:
1
File inclusive
printf("argument list is empty. ,\n";
\

directories areused to include user define


fle inside C program. header
2 The preprocessor commnd for file inclusion
return 0; #include "File name" looks like this:
arguments : File inclusive directory checks included
Properties of command lineare passed to main() function.supplied to the directory (if path is not mentioned). header file inside same
Command line arguments are parameters/arguments
1. arguments 4 File inclusive directives begins
2. Command line 5. with #include
program when it is invoked.are program from outside Ifpath is mentioned then it will include that header file
arguments used to control Scope.
into current
Command line code.
those values inside the
6
3 Instead of using triangular brackets we use
instead hardcoding
of

inclusion of user defined "Double Quote" for


4. argv[arge] is a NULL pointer. program. argvln]
points
1. Itinstructs the compiler header file.
5 argv[0] holds the name of the line
aargument and to include all specified files.
points to first command
the
6 argv[1] directives
last argument 'preprocessor
on
Que 5.31. Writea short note followingp
:
with example
2)
SQ-1 E (Sem-1
&

Problem Solving /SQ-2E (Sem-1 &2)


Programming for
Introduction to to a relatively
cache memory faster main memory, as
2 Marks Questions

1 Components ofA hierarchy accessible to


a. Registers is layered into these
to
layers:
even smaller and
the high speed processing faster
logic. Memory
Computer System C.
Main
b. Cache
memory

Questions) d. Secondary
UNIT (2Marks /axiliary memory
14 Differentiate compiler
processin and interpreter.
components of central AKTU 2017-18
about the (Sem-1), Marks
1.1. Write in brief
computer. What is the difference OR 02
unit ofa are : responsible for carrving between compiler
Components of CPU
Ans. Arithmetic Logical Unit (ALU)
:ALUis and interpreter ?
1. multiplication AKTU 2018-19
: subtraction, (Sem-1), Marks
following operations
operations (addition, Ans: 02|
Arithmetic Compiler
division etc.). XOR etc.). SNo.
(AND, OR, NOT, shift and
clearanee Interpreter
Logical operations
increment, decrement, 1. It is used to compile the
It is used to run
b performs program i.e., to obtain the
It also
to the units. directly on to the the program
control instructions object code from source
C.
operations. machine.
provides
Control Unit: It computer code.
2. structure of a
memory hierarchical Marks 02
2
Intermediate object code No
Draw the (Sem-1), intermediate
1.2, AKTU 2018-19 is generated which is run generated.
code is
system. by SOme other
OR memory hierarchy. application.
structure of
Draw the Pyramid AKTU 2021-22
(Sem-2), Marks 02
15. Define operating system with its different functions.
Ans: An operating systemn
acts as an intermediarybetween the user of a
computer and computér hardware.
Ans (increasing)

Functions of operating system


(decreasing)

Registers
i Memory management
ii. Processor management
Cache ii. Device management
Storage
iv. File management

time Main memory 1.6. Explain the basic structure


Access
Secondary
of a C program.
Give the layout OR
memory
of typical C program,
Fig. l21 ach program begins
Provide information with
preprocessor directives serve to
computer system din a about functions from standard that
definitions of necessary
memory hierarchy of employed
memory
devices 2. Every C1 program constants. libraries and
1.3. Explain the storage auxiliary program consists
The hierarchyconsists of allhigh capacitya
memory selfcontained of one or more
functions. Function is a
Ans:
slow but block off program
computer system from the which performs some kind of task.
Programming for Problem Solving
2)

function ben
3. Every C
program begins with main() function. Every Ang, 2 Marks Questions
S. No. Pseudo code
a return value. following program which gives
4. For example, considerz.the 1 Pseudo code
summation ofx and y as
Directive */ is a natural Flowchart
#include<stdio.h> / Preprocessor language statement A flowchart
8 function prototype for sum() */ that
looks like programming representationis diagrammatic
int sum(int,int); Variables */ for solving of the
int a, b, c; * Global Variable */ code.
the problem.procedure
/* Global type */ The idea is to
š main) function with return
float d; 2.
write in
English what needs
int main() to It isa pictorialrepresentation
Local variables to main() */ happen in code. a programmer uses that
* the procedure for planning
int x, y; for solution
problem.
int z; of
char ch; function call*/ 0 Draw a
flow chart to
Z= sum(x,y); find the greatest
numbers. AKTU2017-18 number among
three
%/
(Sem-1)(Sem-2),
* Definition of function sum() Ans Marks 02
int sum(int x1,int yl)
(Start
Read A,B, C
/* return value of function sum */
return( );

es Is No Is Yes
B> C? A>B2 Yes

1.7.
mean by algorithm ? Explain the
What do you algorithm. No
characteristics of /Print B No
OR
characteristics of an algorithm
? Print C7
What are the good 02
Print A
AKTU 2018-19 (Sem-1), Marks
steps to be
a of instructions which describes the End
Ans. An algorithm is setsolution of a problem. Fig. 1.9.1,
followed to get the :
Characteristics of an algorithm
1.10. Write advantages and disadvantages
1. Input Ansi of flowchart.
Advantages:
2. Output 1. The graphical representation
shows how control of algorithm in the flowchart clearly
3. Definiteness structure operates.
2. Easy to understand.
4. Effectiveness
Disadvantages :
5. Finitenesshr flowchart ?
1. Complex flowcharts
sometimes lead to confusion.
2.
pseudo code and Connectivity issues
in case of largeprograms.
18. What is the difference between 111,
What are
Followingthe four types of storage classes?
Ana,
1. Automatic are the four
2. Register storageclass
types of storage classes :
storage
class
2) SQ-6 E (Sem-1 & 2)
SQ-5 E (Sem-1&
Problem Solving 1.16. 2 Marks Questions
Programming for Differentiate between
algorithm and pseudo
class code.
3. Static storage |AKTU2021-22 (Sem-1),
storage class in o
class
4. External storage Marks 02

static andregister
1,12,
Differentiate between S.No. Algorithm
1. It describes computer Pseudo code
language. program
Register with sequence of steps It write computer
AnC Static understandable form. in English language program in
register to make it
Feature easier.
static 2.
Tt is sequence of steps
Keyword used CPU register explain code.
used to It is representation an
Memory algorithm. of
Storage Garbage value
value Zero value
Default initial Used for loop .4r Differentiate between scope
Used for recursive coünters and lifetime of variable.
Use function |AKTU2021-22 (Sem-1),
a variahlo Marks 02
mean by scope and lifetime of Ans
you Marks 02 a
1.13. WWhat do AKTU 2018-19 (Sem-1), S.No. Scope of
variable Lifetime of a variable
region off program Tt
determine the the
program in 1. determines the area or a It is the
: Scope Peion of code where avariable time for which a
Scope of variables L.e., the part of the
Ang defined object is visible,
name. is available to use.
|variable occupies some valid
in whicha space in
can use the object's lifetime of a variable defines (the
the
the systems memory.
which we : The memory for. it
Lifetime of variables computer allocates memorv) 118. What are
the fundamental data type in
duration for which the deallocation of C Programming
allocation and
duration between and and its range ? AKTU 2020-21
name two syntax of (Sem-1), Marks 02
code, write the Ans:
While compilinga (Sem-1), Marks 02
1.14.
errors. AKTU 2018 19 data types
two logical Range
short int
errors : errors are :
32,768 to 32,767
Ang Syntax frequent syntax unsigned short.
1. Most int 0 to 65,535
Parenthesis ()
a. Missing without declaring it. unsigned int
b. Printing the
value of variable 0
to 4,294,967,295
int
Missing semicolon. error : -2,147,483,648 to 2,147,483,647
C
Example of logical long
int
1.Infinite loop. -2,147,483,648 to 2,147,483,647
by the user. unsigned
long int
2. Wrong input
longlong 0 to 4,294,967,295
components of C language. (Sem-2),
Marks ( int - (2^63) to (2^63)-1
1.15. List the AKTU2018-19 unsigned
long long
signed int Oto 18,446,744,073,709,551,615
: char
AHE Components of C language unsigned 128 to 127
1. Character set char
2.Data type 0 to 255
3. Constants
4. Variables
5. Keywords
KB uestion8
Problem Solving numberg
Programming for
1.19. Write the

1 :Start
algorithm

An8. Step : Declare variable


Step 2
for addition

and b'.
of two
AKTU 2020-21

a, b, sum.
(Sem-1), Marks 02
2
UNIT
Arithmetic Expressions
and Precedence
value 'a' to sum. (2 Marks Questions)
Step 3 :Read assign result
and b' and
Step 4 : Add 'a'
Sum =a+b

Ouantum
Step 5 :
Display sum
Step 6: Stop
2.1. What is an operator ?
AaG Operator is a symbol
that tells the computer to perform certain
mathematical and logical manipulations.
92. What do you mean by operator
ADE Operator precedence determines
precedence ?
which operation is performed first
in an expression with more than one operator
with different
precedence. For example, 10+ 20 x 30 is calculated as
10+ (20× 30)
and not as (10 + 20) x 30.

Series
93. Write difference between implicit and explicit type
casting.
Ans:
s.No. Implicit type casting Explicit type casting
1. It is performed by the It is performed by the
compiler on its own when programmer. The programmer
it encounters
type
a mixed
expression in
tells compiler to type castone data
type to another data type using
data
the program. type casting operator.

2.4. Define else if ladder.


Ans: Else if ladder is the way of putting ifs together when multipath
decisions are involved. A multipath decision is a chain of ifs in
which the statement assöciated with each else is an if.
Syntax: if (cond 1)
stat 1;
else if (cond 2)
stat 2;
else if (cond n)
stat n;
else
default stat;
statx;
2.5. Discuss switch statement C.
in
Solving SQ-9 E (Sem-1 & 2) SQ-10E (Sem-1 & 2)
Programming for Problem
multiway decision statement is known as switch. The 2.11. Define
all 2 Marks Questions
Ans. The built-in (or expression)
of given variablefound.
arithmetic operators.
switch statement tests the value a match is
bloolko
of case values and when AKTU2020-21
against a list case is executed. Ans; Arithmetic en
associated with that
statements i. An
operators : )Ma02
arithmetic operator
conversion. is a
2.6. Define type an entity of a data type into operation namely, symbol which
addition, subtraction, performs an arithmetic
Ans, Type conversion refers to changing # The data on
which such operations etc.
another. Or a constant. are carried
out may be a
statement. statement ox.3 iii. Csupports variable
Define if-else
2.7.
statement is a powerful
decision making
statements.
the arithmetic operators
as given in Table
Ans, The if-else execution of Table 2.11.1. Arithmetic 2.11.1
to control the flow of
is used operators
and associativity whio Operators Symbol
you mean by precedence
What dosome
2.8. expressions ?
Form
Operation
solving arithmetic Marks 02
Multiplication
x*y
AKTU 2018-19 (Sem-1), Division
xtimesy
that xy
are two of the characters x divided
by y
Ang Precedence and associativity
expression for determining
the orde Remainder <%y
an
used for operators in not have brackets. remainder of x
sub-expressions when they do divided by y
operators in C. Addition
Differentiate assignment and equality X+ y y
is added to x
2.9.
AKTU 2018-19 (Sem-2), Marks 02 Subtraction X-y y is subtracted
from x
2.12.Write limitations of switch case.
Ans: Equality operators
S.No. Assignment operators AKTU 2021-22 (Sem-1),
operator. It is a relational or comparison Anst. Limitations of case Marks 02
|It is an assignment operator. 1. A switch
1
float expression cannot be
two tested
5 Switch case can never have variable using a switch case.
It is used for comparing expression.
assigning the value 3. Multiple cases
cannot use same
2. Itis used for values. expression.
to a variable. statement.
switch case 2.13.
Write limitations of subscript operator
2.10. Correlate else if ladder and (Sem-2), Marks 02 in an array.
|AKTU 2018-19 AKTU 2021-22 (Sem-1),
Ans.
Marks 02
Limitations of subscript operator an
Ans. Switch case 1. In C language, we cannot.check, in array :
if ladder are exceeding if the values entered in an array
S.No. Else case, as per the size of that array or not.
control goes In case of switch switch, the 2. If data that is entered with
In else ifladder, the the value of the array size will the subscript operator exceeds the
l. every else if to the it be placed outside the array.
through the control jumps 8. This will lead to unpredictable
statement until it finds true corresponding case. message to warn results. Also, there will be no error
or it the programmer of going beyond the array size.
value of the statement
comes to the end of the else if
2.14.
statement in Find the output
ladder. break of the following code :
use break The use of void main()
2 There is no need to switch is essential.
statement in else ifladder. only integer
data
int a ,$p;
Switch accepts Il value of
Else if ladder accepts integer
a
is input by the user and assumed it equalto
type. is 7.
and character data type.
Programming for Problem Solving SQ-11 (Sem-1 &2)
E(Sem-1&2) SQ-12E 2MarksQuestiong
p= &a; output:
scanf(%d", p); 2.18. Find the
#include<stdio.hs
printf(“od", a);
AKTU 2021-1-22 (Sem-1), int main)
Marks
(2\ int arr[1]=(10};
Ans; 7 printf(“%d/n", O[arr):
return 0;
2.15. Describe the syntax and working of Ternary operator. AKTU2021-22 (Sem-2),
Marks02|
AKTU 2021-22.(Sem-2), Marks 02
Ans: Output: 10
Ans. :
The syntax of ternary operator is Find the output
:
1. 2.19.
#include<stdio.h>
testCondition ? expressionl :expression2;
2. The testCondition is a boolean expression that results in. eithes
int main()
true or false. If the condition is printf(“%d", (void *);
true - expressionl (before the colon) is èxecuted. retur 0;
false - expression2 (after the colon)is executed. AKTU 2021-22 (Sem-2), Marks 02

2.16. Write advantages of switch statement.


Ans: Output :4
AKTU 2021-22 (Sem-2), Marks Find the output ofthe following code:
02
2.20.
void main()
Advantages of switch statement
:
Ans:
1. The switch statement!has a fixed depth. int x = 3, y =4, a=6,2=7,lc;result;
2. It allows the best-öptimized implementation forfaster
code
result =(x> y)ta ||
execution. printf(od", result); (Sem-1), Marks 02
AKTU2021-22
3.
Itiseasy to debug and maintain the programs, compilation because of
error during
4. The switch statement has faster xecutionpower. Ans: This program will give
undeclared identifier o
2.17. Find the output :
#include<stdio.h>
int main)
{

int a = 100;
printf("%d\n" +1, a);
printf(“Value is = od" +3, a);
return 0:
(Sem-2), Marks
AKTU 2021-22
Ahs. Output :

ue is = 100
Programming for Problem Solving SQ-13 (Sem-1
(Sem-1 &2)
&2) sQ-14E 2MarksQuestions
Not necessary to declare too many
variables,

3
2.
are stored ; continuous
3. Array elements in memnory
Demerits of array: location.
Wastage of memory space. We cannot
change size array
Iteration and Loops 9
runtime.
It can store only similar type of data.
of at

UNIT (2 Marks Questions)


3.5. Declare and initialize three dimensional array.
a
Ans: Three dimensional arrayA,,is collection ofp x q xr data elements.
Columns
[A [O, 0, 0] A(0,0, 1] A(0,10] A[0,1,11]|
8.1. List three types of loop control statement in
C.

Rows A(1, 0,0] A[1, 0, 1] A(1,1, 0] A1,1,1]|


Ans
1, The while statement
2. The do-while statement R6. Write the difference between structure and union.
3. The for statement AKTU 2018-19 (Sem-1), Marks 02

3.2. Differentiate while and do while loop. OR


Differenmce between structure and union.
AKTU2018-19 (Sem-2), Marks 02
AKTU 2020-21 (Sem-1), Marks (2
OR
What is the difference between while and do-while loop ? Ars
AKTU 2020-21 (Sem-1),Marks 02 S.No Structure Union
1 A structure is
a
collectionIt is a collection of data items of
Ans: of data items different
of different data types. It handles only
Ithandles a one member at a time.
S.No. While loop Do-while loop data,types.
group of logically related
1 While loop is used to Do-while loop is used to execute a
set ofstatements repeatedly, until datai tems.
execute a set of
statements repeatedly, as the logical test result is false. have the same
Bach member has its.own AllLthe members
long asthe specified storage location.
condition is true. storagelocation.
? Explain.
2. It is entry control loop. type in C
language
It is exit control loop. 3.7. What is an enumerated adata It
C. is mainly
Ans: user-defined datatypeeinnames make a
Enumerationt (or enum) is constants, the
3.3. Why we use do-while loop properties used to assign names to integral
in C? Also tell any
02 Program easy to read and maintain.
which you know ? AKTU 2017-18 (Sem-1), Marks type.
enumerated data types.
Ans: The do-while loop is
always want to
executea block 38, Write
notes on union and of different
data
of code at least once.
used when we
Ans: short data items
usual
:
Union:Union is a collection of SQ-14E,
Unit-3,
Itis a loop with the test at the bottom, rather than the more It handles only one data at a time. Q. 3.7, Page
Refer
test at the top. That is, it is an exit control loop. Enumerated data types ::
Two Marks Questions. some sort
3A. What are, the merits and demerits array Explain with
Ans: Merits array
of :
of n o. 3.9,
Howto use break statementtin
C?
2018-19
(Sem-1), Marks
02|

1. We can
easily access AKTU
each element of array. of code.
Programming for Problem Solving SQ-15 (Sem-1 (Sem-1 &2)
E &2) SQ-16E
2MarksQuestions
OR
Each node in linked list is divided intotwo
Explain the need of in switch statement
break AnE
contains the information of the element parts:thefirst part
with
AKTU 2020-21 (Sem-1), called the link field the next pointer field,and the second part.,
or
example. Marks 02 contains
of the next node in the list. Linear order the address
of node
OR links or pointers. is maintained
by
Head
Show the usage of break statement.
AKTU2021-22 (Sem-1), Marks
02 Data Next Fig. 3.11.1.
Ans1.
The break statement is used to terminate loops or to exit
sitch statement. It can be used within for, from a 10-Write the syntax of continue statement.
while, do-while o
switch statement. AKTU 2020-21 (Sem-1),
2. Abreak used in a switch statement will Marks 02|
affect only that switch AE Syntax continue statement:
of
3. In a loop statement when break is encountered,
the loop is IMoop statements
immediately terminated, and program controlresumes at the next
statement following the loop. continue;
llsome lines of the code which is to be skipped
For example:
#include<stdio.h> 3.13. What are subscripts ? How are they specified ?
#include<conio.h>
int main AKTU 2017-18 (Sem-2), Marks 02|

eS
Ans: Subscripts (or index) indicate the position of an element in an
int a; array. Subscript is specified within a square bracket and begins
for(a = 0; a< 100; a++)
printf("%d, a);
if(a ==10)
break
from 0.

Serie
getch);
return 0;

3.10. What is an array ? In which situation array


advantageous over linked list ?
|AKTU2018-19 (Sem-1), Marks 02
Ais Array : An array is a list of finite number ofelements ofsame vo
type i.e., integer, real or
Array is advantageous strings. access of
over
linked list : Duringtthe because
particular element, array
is advantageous over linked list
1n array we can access ofindex but
element directly with the help
in linked list we cannot access the element directly
3.11. Define
the structure of a node in linked
ist. 02
Sem-2), Marks
|AKTU 2018-19
SQ-18 E (Sem-1& 2)

Solving
SQ-17E (Sem-1&2)
2 Marks Questions
Programming for Problem Ans.
S.No. Actual arguments
1
Actual arguments Formal arguments

4 UNIT (2 Marks
Functions
Questions)
2.
arguments present are
calling program. in the
The actual arguments
the things that the are
actually passes tocaller
function. the
Formal arguments

The formal arguments


are arguments
present in called program.

parameters specified are the


function definition. in the

For example :The function


value(500, 0.12, 5) call
ofusing multinle
arefunctions? Whatis the advantage would send the values
4.1. What
program ? void value(iloat p, float500,
r,
0.12 and 5 to the function
functions in a statements that take inputs,
do some specifc and assign 500 to p, 0.12 int n)
Ang, Function is a set of output. are the actual arguments, to r and 5 to n. The values
computation and produces program : 500,0.12 and
functions in a arguments inside the calledwhich become the values of the formal5
Advantage of using multiple function.
encourages code-reuse. maintainability. A5.
1. 1t robustness and Explain function declaration
2. Code-reuse can aid in semantics ofthe function. and definition of a function
3. Easier to understand the with example. |AKTU2017-18 (Sem-1), Marks 02
Define function and its
type. A: A function declaration
tells the compiler
4.2. Marks 02 return type, and parameters. about a function's name.
AKTU 2021-22 (Sem-2), Example : int max(int num1, int num2);
Two Marks A function definition
SQ-17E, Unit-4, provides the actual body
Ans Q. 4.1, Page Example : int max(int num1, int of the function.
A. Function Refer /* local variable declaration num2) {
Questions. */
B. Types of function:
int result;
library function if (numl > num2)
i Standard
User-defined functions result = num1;
i. else
given program : resúlt = num2;
43. Predict the output of return result;
int sumn (int n)
if
(n<1) return;
else return (n + sum (n-1); 4.6. Write a function to
interchange the two values of two
variables without using
main ()
third yariable.
Ans: void AKTU 2017-18 (Sem-1),Marks 02
printf (od", sum (5)); main()
}
int a,b;
Ans 15. formal printf(“Enter
argumnents and scanf(“%d" the value of a:");
4.4. Distinguish between actual Marks 08/
&a);
printf(“Enter
arguments with the help of example. (Sem-), the value ofb:");
2017-18 AKTU
SQ-19E (Sem-1& 2) SQ-20 E (Sem-1 &2)
Solving
Programming for Problem 2 Marks Questions
4.10. Explain function prototype.
scanf("%d",&b); Why is it required ?
a
=a + b; AKTU 2017-18 (Sem 2),
b=a-b;b: Ans: A function prototype
is a function
Marks02
a=a- datatypes of its arguments declaration that specifies
of a: %d",a); Function prototype is in the parameter list. the
printf(“"The value %od",b); required because :
printf(“\nThe value of b: 1. It tells
the return type of the data
C language ? 2. It tells the number that the function will return.
you mean by formatted output in 3. It tells of arguments passed to
the data types of the each of the function.
4.7. What do Marks 021
AKTU2017-18 (Sem-2), 4 Ittells the order in which the arguments the passed arguments.
Explain with example. standard are passed
to
the
formatted output to the
function.
printf ) function sends function. It is declared i 4.11. Write the use of putchar() and getchar().
Ans. The is a library
output (screen). The printf()
"stdio.h header file. AKTU 2017-18 (Sem-2),
Marks 02
For example
: run printf( ) function Ans: putchar):
is needed to 1
putchar() function is used to write a
#include <stdio.h> / This character on standard output/
Screen,
int main()
2. In a C program, we can use putchar() function as :

programming"); putchar(char);
printf("C where, char is a character variable/value.
return 0;
getchar)
:

1., getchar() function is used to get/read a character from keyboard


:
Output input.
C programming files. Write its syntax? 2. In a C program, we can use getchar function as:
What is the use
offseek() function in getchar(char);
4.8. Marks 02
AKTU 2017-18 (Sem-2), where, char is a character variable/value.
a given file to
used to move file
pointer associated with 4.12. Write a recursive function an
Ans, fseek() is position. C,
a specific user to calculate a factorialinusing
which takes input from
the recursion concept.
: position)
Syntax *pointer, long int offset, int identifies the stream. AKTU 2018-19 (Sem-1), Marks 02|
int fseek(FILE pointer to a FILE object that Ans. #include<stdio.h>
where pointer: to offset from position.
offset: number of bytes
main()
from where offset is added.
position: position
following : int n,f;
4.9. Write down the output of the clrscr( );
main( ) printf("\nEnter any number:";
scanf("%d", &n);
inti= 1; f= factorial(n);
for(; ;) printf(“\nfactorial =%d",);
getch( );
printf(“od", î); return 0;
if(i == 7) factorial(int n)
break;
2017-18 (Sem-2),
Marks 0
|AKTU
1111
printing l if(n == 0)
on
program will keep
Ans. Output: 1 111111(The
11 continuously).
SQ-21 E (Sem-1 &2) SQ-22 E (Sem-1 & 2)
Solving
Programming for Problem 2 Marks Questions
For example,
return(1); array is calledconsider
to be in
an array A = {A1,
A2, A3, A4, ... ,
else factorial(n 1)): - like A1> A2>A3 > ascending order if element ofA are
An), the
arranged
return(n * A4.>....> An.
A16. Differentiate
between void and
and iteration. int datatypes.
Differentiate recursion Marks 02 AKTU2021-22 (Sem-2),
4.13. AKTU 2018-19 (Sem-2), An8. Marks 02
S.No. int main ()
Iteration void main ()
Ans. 1. The return type of the
Recursion process of executing function is "int" i.e., it is The return type of the
S. No. It is a is "null" i.e., the value function
technique ofdefining statement until some specified supposed to return an
Itis a ofitself. function is returningwhich the
anythingin terms condition is satisfied.
1
integer to the operating null value. will be a
system.
to It is applied to loops.
applied
2 It is always 1 Define time and space
functions. complexity. What is the complexity
search. of bubble sort ? |AKTU2021-22 (Sem-2), Marks
Differentiate linear and binary 02 Time complexity : The time complexity 02
4.14. AKTU 2018-19 (Sem-2), Marks the amount of time taken of analgorithm
by an algorithm to run asa quantifies
OR the length of the input. function of
search in terms of complexity. Space complexity:The space complexity of an
Compare linear and binary 02 the amount of space taken by an algorithm quantifies
AKTU 2021-22 (Sem-1), Marks algorithm tO run as a function
the length of the input. of
Complexity of bubble sort :
Ans 1. Complexity
in best case is O(n).
Binary search
Sequential (Linear) search
2. Complexity in worst case
No.
is On).
Elementary condition i.e., 3. Complexity inaverage case is
S.

1. No elementary
condition i.e.,
array should be sorted.
On).
array canbe sorted or unsorted.
to search an
time to search an It takes less time
2. It takes long element.
element.
Complexity is O(log, n).
3.
Complexity is O(n). and
on divide
linearly. It is based
4. It searches data conquer method.

4.15. Define sorting algorithm


with example.
(Sem-1), Marks 0
AKTU2020-21
format
desired
Ans: Sorting : a process of arrangement of data in
1.
Sorting is element
vdesired
(increasing or decreasing). any
we can search
2.
The usefulness of sorting is that
efficiently.
Solving sQ-23 (Sem-1&2)
E
SQ-24 E (Sem-1 &2)
Programming for Problem
Ans: Pointer a 2 Marks Questions
Variable.isA pointer
variable storcs/points
is used to allocate memory
the addres8 of another

5
runtime. dynamically
Syntax: i.e., at
datatype *var_name,
Pointers Difference between
stored at address p*p++ and ++ *p is that in *p++ first
UNIT (2 Marks Questions) incremented. In case will be given after that addressthe value
incremented first. of ++*p, value stored will get
at address p will be
54. What is void pointer
? How is it different
with example. pointers ?
5.1. Define double pointer address of another pointer then such Ans. A void pointer a
from other
holds theas is
poown
Ans: Whenofa pointer double pointer or pointer-to-pointer, It A
void pointer can pointer that has no associated data type
hold address of any type
type asterisks (**). to any type. and can be typewith
a
it.
represented by two
is Difference :
casted
For example,
main) Void pointer Null pointer
Void pointer is a pointer Dangling pointer
A
null pointer is a A dangling
int p; which is used for generic
pointer which used pointer is a
int *q nrogramming in C. can is pointer which points to
It to report an error- a memory
int **r; be assigned to or from condition. free block or
p= 27; pointers of any type. to a variable gone out
q= &p; of scope.
r= k; 5.5.
printf“%3", p); #define PRODUCT(n) n *n
printf("%3", *q); void main()
printf("%3", **r);
27 printed three times:
int j;
The result is the value j=64/PRODUCT(4);
272727 printf(“%d", j);
}

differ from text files ?


5.2. How binary files What will be the output of
the above program?
Text file AKTU 2017-18 (Sem-1),
Marks 02
s. No. Binary file textual Ans: 4
stores theA text file stores the alphabetS,
1. A binary file binarylinformation like 5.6. Give advantages
information in the formatnumbers, special symbols, et Ans Advantages of
of pointers.
same
form, i.e., in the memory. 1. More efficient pointers:
as it is stored in the data in handling arrays and data tables.
need of file 2. Allow C to support
requires the text dynamic memory management.
It eliminates the need of data It
3. Reduce
from the
conversion binary form
before
4. Efficient
length and complexity of programs.
conversion fromtext to binary to storage device tool for manipulating dynamic data structures like
Contents lists, queues, stacks linked
format for storage purpose. in the
being stored between and structures.
difference O:. Mention some
is pointer variable
? Explain the Ans File handling file handling functions.
5.3. What 1. fopen( functions :
*p++ and ++*p. )
SQ-25E (Sem-1 & 2) SQ-26 E (Sem-1 &2)
Problemn Solving
Programming for 5.12. 2 Marks Questions
Define preprocessor
)
and its usage in programming.
2. fclose(
getc( ) AKTU 2020-21
3. Ans: (Sem-1), Marks
putc( ) 1. Preprocessor directives 02
4.
fscanf are lines included
5. with the character #. in a program
6. fprintf() 2. Preprocessor that begins
preprocessor directives. directives follow special
from the normal C syntax. syntax rules that are different
three types of preprocessor directives:
5.8. Mention types of
are three
Ans. Following
substitution directives
B13. Write the
advantage for the use
1. Macro directives of linked list.
2. File inclusion directives AKTU2020-21 (Sem-1),
Compiler control Ansi Following are Marks 02
3.
self-referential structure of the advantages for the use
1 Linked list is a dynamic of
linked list ? Write the 02 data structure so it can growlinked list :
5.9. What is (Sem-1), Marks runtime by allocating and and shrink at
AKTU 2018-19 9. Insertion deallocating memory.
a node in linked list ? of the same data and deletion of nodes are easier.
linked list is a collection ofrecords(a variable which g As size
of linked list can increase or decrease
Linked list :A are connected by
pointers a

at run time so there


Ans. type, and all the records is no memory wastage.
memory address). :Self-referential structures are those B14. What is the requirement of FREE0 function
holds a to the same
Self-referential structure
one or more pointers which point memory allocation.
in dynamic
structures that have AKTU 2021-22 (Sem-2),
as their member. Marks 02
Ans The Free() function is used to free a
type of structure, in C? portion of storage within the
difference between.obj and.exe files heap previously allocated by alloc), malloc), calloc) or
realloc ().
Marks 02
5.10. WWhat is the AKTU2018-19 (Sem-2), 5.15. Explain the significance of End of File (EOF).
|AKTU2021-22 (Sem-1), Marks 02
Ans: Executable file (.exe) Ans. End of File (EOF) are helpful
Obiectfiles (.obj) capable of in data transmission and storage.
Files are stored in blocks, and EOF helps the computer
A file that is
S.No. know it
indicated tasks
thatcontains an object performing the has allocated enough space to store the file.
1. A file relocatable encoded
code that has according to the
code, which is 5.16.Differentiate static and dynamic memory allocation.
format machine instructions.
directly executable.
not AKTU 2018-19 (Sem-2), Marks 02
intermediate file. It is a final file.
executed by Ans
2. It is an can be directly
cannot be directly
executed It S.No. Static nemory allocation Dynamic memory allocation
3. It the CPU.
by the CPU. In this case, variables get In this case, variables get
significance of null
character in string
Marks 02
allocated permanently.
allocated only if our program
5.11. Explain the 2018-19 (Sem-2), Therefore, unit gets active.
AKTU zero. 2 Allocation is done
set to representthe before Allocation is done during
its bitsused to
character with allcan helps program execution.
program execution.
AnE A
null character isa zero and be
phrase.
This 3 Stack is used
a numeric value of or for
it has
of characters, such
as a word static allocation. implementing Heap is used for implementing
end of string length of strings.
a
dynamic allocation.
programmers to determine the
the
Programming for Problem Solving SP-1E (Sem-1&2)
SP-2E (Sem-1&
2)
B.Tech. Solved Paper
(Sem-1)(2017-18)
(SEM. I) ODD SEMESTER THEORY What will
be the output
Ans. Refer
EXAMINATION, 2017-18 Q. 5.5, Page of the above program
SQ-24E, Unit-5, ?
Two Marks Questions.
COMPUTER SYSTEM & PROGRAMIMING SECTION-B
2. Attempt any
INC a. What three of
functionsis operating thefollowing:
system ?
Max. Marks:70 Explain various(7 3= 21)
Ans; Refer Q. performed by an operating
Time :3 Hours 1.9, Page 1-12E,
Unit-1. system. types of

Note: 1. Attempt all Sections. Ifrequire any missing data; then choose b. Discuss various
suitably. examples. data types used
Ans: Refer Q. in C with suitable
1.36, Page
SECTION-A 1-36E, Unit-1.
c. Write a program
C to add first seven terms
1.Attempt all gquestions in brief.
(2 x7=14) series using for loop. of the following
arguments and formal 1/1! + 2/2!+ 3/31+.
a. Distinguish between actual Ans: Refer Q. 3.5, Page
arguments with the help of example. 3-4E, Unit-3.
Ans; Refer Q. 4.4, Page SQ-17E,
Unit-4, Two Marks Questions.
d. Define the concept
a memory allocation of pointer. Also, define the dynamic
b. Explain function declaration and definition of function memory allocation and various functions
with example. Ans. Refer Q. with suitable example. for dynamic
Unit-4, Two Marks Questions. 5.12, Page 5-11E, Unit-5.
Ans: Refer Q. 4.5, Page SQ-18E,
greatest number among three e Write a Cprogram to sort
C.Drawa flow chart to find the order by using bubble sort set of integers in ascending
technique.
numbers. Unit-1, Two Marks
Questions. Ans. Refer Q
4.23, Page 4-21E, Unit-4.
Ans. Refer 1,9, Page SQ4E,
Q.

of two SECTION-C
d. Write a function
to interchange the two values
variable.
variables without using third
Unit-4, Two Marks Questions.
3. Attempt any one part of the following :
Ans. Refer Q. 4.6, Page SQ-18E,
Un
a
Write program to check the number is
not. The program should accept any
(7xl=7)
palindrome or
arbitrary number
e. Differentiate compiler and interpreter. Questions. typed by user.
SQ-2E,Unit-1, Two Marks Ang: Refer Q. 3.6, Page
Ans. Refer Q. 1.4, Page 3-5E, Unit-3.
any propere
Why we use do-while
loop in C?Also, tell D. Write a program to check a numnber is prime number or
f.
not,
which you know ? Questions.
SQ-13E, Unit-3, Two Marks Ans: Refer Q. 3.7, Page
3-6E, Unit-3.
Ans. Refer Q. 3.3, Page
#define PRODUCT(n) n *n Attempt any one part of the following :
4.
g. (7x1=7)
d
What is recursion ? Write a program to print the Fibonacci
void main() series using recursion.
Ans Refer Q. 4.14, Page 4-15E,
int j; Únit-4.
j=64/PRODUCT(4);
printf(“%d", j;
SP-4 E (Sem-1&2)
SP-3 (Sem-1&2)
E
Solved Paper (Sem-2)(2017-18)
Solving
Programming for Problem passing B.Tech.
between parameter Which is (SEM. II) EVEN
Explain the difference and call by reference. SEMESTER THEORY
b. value
mechanism call by why ? EXAMINATION,
more efficient and4-12E, Unit-4. COMPUTER SYSTEM 2017-18
4.10, Page (7x1 = 7) & PROGRAMIMING
Ans. Refer Q. following:
any one part of the matrices (read size and INC
5.Attempt multiply two
program to matrices from the keyboard).
a. Write a of Unit-3. Time :3 Hours
number of element
Page 3-20E, Max. Marks:70
Ans. Refer Q.
3.24,
AIso, write
a program that
sav
sta: Attempt all sections.
If require any missing data;
structure with syntax.store date use structure
month and
suitably. then choose
Define
b. compares two given dates. To date,
membersnamely message as “Equal" SECTION-A
that contains three then display
date dates are equal
year. If the"Unegqual". 1. Attempt all questions in brief:
otherwise 3-28E, Unit-3. What is token in C language ? (2 ×7= 14)
Q. 3.33, Page
7)

Ans. Refer following:


(7x1= This question is out of syllabusfrom session (2022-23).
Writea
any one part of the opening modes in C? file. h What do you mean by
6. Attempt different file one into other
file formatted output in C language
a. What are the contents of Explain with example.
?
program to copy the
5-23E, Unit-5. Ans Refer Q. 4.7, Page SQ-19E, Unit-4, Two Marks Questions.
5.23, Page explain mãcro
Ans. Refer Q. substituted ? Also, help
is it act as a function with the
macro ? Howmacro What is the use of fseek() function in files. Write
its syntax?
b. What is variable and Ans: Refer Q. 4.8, Page SQ-19E, Unit-4, Two Marks Questions.
act as a
of exanple. Page 5-31E, Unit-5. d. Write down the output of the following.
Refer Q. 5.29, (7x17) main()
Ans. following digital
any one part of the Draw block diagram of
7. Attempt computer ? components of it. inti = 1;
What is digitalexplain each
a. computer for(; ;)
and 1-3E, Unit-i.
Q. 1.1, Page ? Define all
Ans: Refer classes of a variable printf(“9%d",i);
meant by storage
example. ls if(i ==7)
b. What is storage classes with break;
types of 1-39E, Uit-1.
1.39, Page
Ans. Refer Q.
Ans: Refer Q. 4.9, Page
SQ-19E, Unit-4, Two Marks Questions.
e Explain function prototype.
Ans: Why is it required ?
Refer Q. 4.10, Page SQ-20E,
Unit-4, Two Marks Questions.
L What are subscripts
as Refer Q. 3.13, Page
? How are
they specified 7
SQ-16E. Unit-3, Two Marks
Questions.
Programming for Problem Solving SP-5E (Sem-TC

g. Write the use of putchar() and getchar(). AKS: Solved Paper


Two Marks Questions. This question (Sem-2)\(2017-18)
Ans. Refer Q. 4.11, Page SQ-20E, Unit-4, is out of syllabus
from session
4. Attempt (2022-23).
SECTION-B a. Explain any one of
different the following:
bitwise
(7 x3 = 21) examples. operators available (7x 1= 7)
following: Ans. Refer Q. 2.1,
Attempt any three the
of
2. number of elements Page in C with
a. Write a program in C to find the largest 2-2E, Unit-2.
in 4 *4 matrix.
b. What is meant byy
3-27E, Unit-3. Explain about type conversion
Ans. Refer Q. 3.32, Page examples. implicit and explicit ? Why is necessary ?
type conversion
use of the following directives with Ans. Refer Q. 2.5, Page with
b. Explain the syntax and 2-6E, Unit-2.
examples : 5. Attempt anyone of the following :
i. #ifdef
iü. #undef a. Write a program
iv. #include to find the Armstrong (7x1=7)
ii. #pragma 5-28E, Unit-5.
1 to 100.
number from
Ans: Refer Q. 5.27, Page Am8: Refer Q. 3.8, Page 3-6E, Unit-3.

short note on
:
Write b. Write a program
development approach
C.
program to generate a following
i. Top-down structure and array structure : numbers
ii. Differentiate 12345
(2022-23). 1234
Ans:
i. This question is
out of syllabus from session 123
3-27E, Unit-3.
ii. Refer Q. 3.32, Page 12
program in Clanguage to print Fibonacci
Ans: Refer Q. 3.9, Page 3-7E, Unit-3.
d. Write a recursive
series. Attempt any. one of the following:
6.
4-15E, Unit-4. a.
Write a program to add two
Ans. Refer Q. 4.14,
Page
store the result in another matrices of dimension(7*1=)
3*3 and
What are the main
steps followed in matrix.
Ans: Refer Q. 3.28, Page 3-24E, Unit-3.
e. What is algorithm ?an algorithmn ? Write an algorithm for
the development of number.
sum of digits in a given Unit-1 b. Write à program in C to create a
Page 1-20E, to store personal details such as database of fifty students
Ans. Refer Q. 1.19, Print all the details of student roll no, name and marks.
SECTION-C whose name is entered by
user.
(7xl=7) Ang. Refer Q. 3.34, Page
3-29E, Unit-3.
3. Attempt
any one part of the following: Write the names
a. Describe compiler,
interpreter, assembler. 7. Attempt any one
of the following : (10 x 1=10)
are used in C programming. a. Write a program C to reverse a string by using pointer.
of compiler that Ans Refer Q. 5.6, Page in
1-15E, Unit-1.
Ans: Refer Q. 1.12, Page 5-6E, Unit-5.
: b. Explain the following functions in file operations :
b. Convert the following
= O8 i. getw)
i. (0110110.1100), = iüi. fscanf( ) ii. putw()
ii. (74.67)0 )16 Ans Refer Q. 5.21, iv. fprintf)
(AB.CD),6 Page 5-20E, Unit-5.
ii. = (0%
iv. (EFE.45)16
v. (576.4)10
=(O16
vi. (1234.7),
vii. (334.43),
SP-7E (Sem-1&2) SP-8E (Sem-1 & 2)
Solving Solved Paper (Sem-1)(2018-19)
Programming for Problem i. Write the differonce
Ans. Refer Q. 3.6, hetween structure
B. Tech. Page SQ-14E, Unit-3, and union.
SEMESTER THEORY Two Marks Questions.
I) ODD
(SEM.EXAMINATION, 2018-19
lk Draw the memory
hierarchical structure
systom. of computer
PROBLEM SOLVING Ans Refer Q. 1.2,
Page SQ-1E, Unit-1, Two
PROGRAMMING FOR Marks Questions.
:
Max. Marks 100 SECTION-B
2. Attempt any
Time:3 Hours choose three of the following :
If require
any missing data; then a. Explain
linear search and binary (10 %3 = 30)
sections.
Note: Attempt all searching an item in a given array. search technique for
suitably. complexity for each searching Also write the
Section-A Ans: Refer Q. 4.18, technique.
Page 4-18E, Unit-4.
(2 x 10 = 20) b. A certain grade
in brief:
2

Attempt all questions between compiler and interpreter


of
steel graded according to the following
1.
a. What is the difference Questions. conditions :
Unit-1, Two Marks i.
Hardness must be greater than 50,
Refer Q. 1.4, Page SQ-2E, i#.
Ans. ? algorithm Carbon content must less than0.7.
good characteristics of an iii. Tensile strength mustbe be less
b. What are the
Questions.
The grades are as follows : than
5600.
Unit-1, Two Marks
Refer Q. 1.7, Page SQ-3E,
Ans. ? Grade is 10 if all the three conditions are
mean by scope and lifetime of a variable Grade is 9 if condition (i) met.
What do you Two Marks
Questions.
Grade is 8 if condition (ii)
and (ii) are met.
Page SQ-5E, Unit-1, and (iii) are met.
Ans. Refer Q. 1.13, Grade is 7 if condition (i) and
an input from (iii) are
Write a recursive function in C, which takes
recursion concept. Grade is 6 if only one condition met.met.
d. the is
user to calculate a factorial using Two Marks Questions. Grade is 5 if none of the conditions are met.
Page SQ-20E, Unit-4, Write a program, which will user to give values
Ans. Refer Q. 4.12, some sort of hardness, carbon contentrequire the
statement in C? Explain with and tensile strength of the
steel under consideration and output
e How to use break the grade of the steel.
Questions. Ans. Refer Q. 2.21, Page 2-22E,
of code. Unit-2.
SQ-14E, Unit-3, Two Marks
Ans. Refer Q. 3.9, Page
c, What do you mean by call by
mean by precedence and
associativity while value and call by reference ?
£ What do
you Write an algorithm for
solving some arithmetic
expressions ?
Marks Questions. by reference technique.swapping two numbers using call
Ans: Refer Q. 2.8, Page SQ-9E, Unit-2, Two above Also write a C program
for the
stated algorithm.
the name of two syntax and Ahs: Refer Q.
4.8, Page 4-11E, Unit-4.
g Whie compiling a code, write
two logical errors.
Two Marks Questions.
. Explain selection sort technique
Ans: Refer Q. 1.14, Page SQ-5E, Unit-1. write an algorithm for for sortingproblem. Also
array In which situation
?
array
humbers using selectionselection sort. Sort the following
sort technique 26, 54,93,
h. What is an 44, 55,20. 17, 77,31,
over
advantageous linked list ? Questions. As: Refer Q. 4.25.,
Ans. Refer Q. 3.10, Page SQ-15E, Unit-3, Two Marks Page 424E, Unit-4.
structureof e
self-referential Write a
i.
What is linked list ? Write the short
with example: note on following preprocessor directives
a node in linked list ? Questions.
Marks
Ans: Refer Q. 5.9, Page SQ-25E, Unit-5, Two
Solving SP-9 (Sem-1& 2)
E
SP-10E (Sem-1
Programming for Problem & 2)
ii. String: Refer Q. Solved Paper
(Sem-1)\2018-19)
i. Macro expansion 3.29, Page
3-24E, Unit-3.
ii. File inclusionPage 5-34E, Unit-5. b. What do you
5.31, notions mean by
Ans. Refer Q. order
Ans. Refer Q. to represent order of complexity ?
SECTION-C 4.24, Page of complexity Explain
4-22E, Unit-4. various
× 1 = 7. Attempt any
with diagram.
following : (10 10) one part
a. What
any one part of the system with of the following :
3. Attempt components of computeryou mean bv is dynamic memory
malloc), realoc()
a. Describe the basic diagram. Vhat do 11fetimne allocation ? Explain (10 ×1 = 10)
and free() functions
neat and clean block
Explain. of a variable,
which
the
in detail. calloc).
operating system ? 4n Refer Q. 5.13, Page 5-13E, Unit-5.
is created dynamically What is
Unit-1.
1.9, Page 1-12E, ?
Ans. Refer Q. Explain command
data types in
C. Discuss primitive and range. line arguments
data types in
b. Define memory occupied, format specifier example. in C with the
AnRefer Q. 5.30, Page 5-33E, Unit-5. help of
terms of Unit-l.
1.36, Page 1-36E,
Ans. Refer Q. (10 1=10) x
following:
any one part of the
Attempt arithmetic operators intwoC
4 Explain various
a. types of precedence of
help of example. When
language with an arithmetic expression is
same, bor
will be
operators in which operator
associativity helps in identifying

Dua
with the example ?
it
evaluated first. IllustrateUnit-2.
13, Page 2-14E,
Ans. Refer Q. 2. the case reason
structure in C? What iscase
b. What is case control
statement at the end of each in
for using break
control block ? 2-23E, Unit-2.
2.22, Page
Ans Refer Q. (10 x 1 = 10)
following:
any one part of the for loops.
while anddimension
5. Attempt for while, do
a. Write the syntax format a matrix of
Write a
program in C to multiply matrix.
store the result in
another
4*4 and Unit-3.
3.24, Page 3-20E,
Ans Refer Q. prorammers use functions
in
are
a function ? Why the values
how
b. What is executing a function, ?
code ? While calling and called environment
passed between 4-12E, Unit-4. = 10)
Ans Refer Q.
4.9, Page (10x 1
following :
Attempt any one part of the
6 on following :
a. Write short notes
1. Enumerated data type Unit-3.
2. String 3-35E,
Q. 3.38, Page
Ansi. Enumerated data type: Refer
Solving SP-11 E (Sem-l &2) SP-12E (Sem-1&
Programming for Problem 2)

B.Tech. Solved Paper


(Sem-2)(2018-19)
SEMESTER THEORY
SECTION-B
2. Attempt
(SEM. ID EVEN a. Draw any thrce of the following:
EXAMINATION, 2018-19 the
different block diagram of a computer
SOLVING Ans: Refer Q. components with (7x3 = 21)
PROGRAMMNG FOR PROBLEM 1.2, Page 1-5E,
Unit-1.
system. Explain
suitable example. its
Max. Marks: 100 h. Differentiate
a program operator precedence
Time:3 Hours in C to elaborate
logical QR operators and associativity.
the use of
Ifrequire any missing data;
then choose Ans: Refer Q. 2.16, in C. logical ANDWrite
1. Attempt all Sections. Page 2-17E, Unit-2. and
Note: suitably. Whatis the use
SECTION-A in Cusing whileof breakstatementin loops?
loop to Writea program
AnE; Refer Q. 3.19, Page 3-15E,elaborate the use of break statement.
(2 x7= 14) Unit-3.
brief. .exe files inC?
1. Attempt all questions in
between .obj aid A
Write a program
a. What is the difference Marks Questions. nser and print inC to input two 3
PageSQ-25E, Unit-5, Two (Write comments multiplication is x3 matrix from the
Ans. Refer Q. 5.10, also at the result in matrix form.
Ane: Refer Q. 3.24, Page appropriate
components of C language. Marks Questions. 3-20E, Unit-3, places in the program).
b. List the SQ5E, Unit-1, Two
1.15, Page Explain the importance
Ans Refer Q. operators in C.
of pointers in C.
assignment and equality Questions.
it in C to swap
Cc. Differentiate
Unit-2, Two Marks using functionthe values of two numbers Write a program
Ans; Refer Q. 2.9,
Page SQ-9E,
Ans:
call by reference method. entered by user
Refer Q. 5.7, Page 5-8E, Unit-5.
case statement.
ladder and switch
d. Correlate else if SQ-9E, Unit-2, Two Marks Questions.
Page SECTION-C
Ans: Refer Q. 2.10,
while loop. 3. Attempt any
one part of the following:
e Differentiate while and do Marks Questions. a. Write an
Page SQ13E, Unit-3, Two algorithm (7x1=7)
Ang Refer Q. 3.2, digits of an integer and draw a flowchart to find the sum of
iteration. number entered by user,.
Differentiate recur'sion and Questions. Ans. Refer Q. 1.21, Page 1-22E, Unit-1. the
f Page SQ-21E, Unit-4, Two Marks
Ans Refer Q. 4.13, string. b. Write an algorithm
null character inQuestions. and draw a flowchart to reverse
g. Explain the significance of Unit-5, Two Marks
integer number entered by the user. an
Q. 5.11, Page SQ-25E,
Ans: Refer Q. 1.24, Page
Ans Refer 1-24E, Unit-1.
Differentiate linear and binary
search.
h. Two Marks Questions. Attempt any one part
Ans: Refer Q. 4.14,
Page SQ-21E, Unit-4, a. Define of the following:
the term mixed operands an (7x1=7)
Differentiate static and dynamic memory allocation.
Questions.
WIth few examples.
of type casting.
in arithmetic expression
Write program in C to
SQ-26E, Unit-5. Two Marks
i. elaborate the use
Ans: Refer Q. 5.16, Page
AS; Refer Q.
2.7, Page 2-8E,
a linked list. Unit-2.
j. Define the
structure of node in Questions. b.
Explain
SQ-15E, Unit-3. Two Marks programthe use of default in
Ans. Refer Q. 3.11, Page switch statement. Write a
that takes two
the useraand operands and one
using switch perform the operation and printsoperator
statement.
from
the result by
SP-14 (Sem-1&2)
E

Solving
SP-13E (Sem-1 &2) Solved Paper (Sem-1)(2020-21)
Programming for Problem
2-23E, Unit-2. B. Tech.
Q. 2.23, Page (SEM. I) ODD SEMESTER
Ans. Refer following: (7x l =7) THEORY
any one part of the following pattern with EXAMINATION, 2020-21
5. Attempt program in C to print PROGRAMMING FOR PROBLEM
a, Write a comments :
appropriate SOLVING
10 Time :3 Hours
Max. Marks: 100
99
765
Note: Attempt all sections. If require any
suitably. missing data; then choose
4321
3.10, Page 3-7E, Unit-3.
Ans. Refer Q. Explain complier,
assembler. SECTIONA
concept of example.
b. Discuss the linker with
interpreter, loader andUnit-1,
1. Attempt all questions in brief :
a. What are the fundamental (2% 10 = 20)
1.16, Page 1-18E, data type in CProgramming
Ans. Refer Q. (7x1=7) a range.
following: Write and its
any one part of the problem solving.numbers Ans: Refer Q. 1.18, Page SQ-6E, Unit-1, Two Marks Questions.
6. Attempt importance of sortingin sort 10
a. Write the sort technique to
program in Cusing bubble b. Write the algorithm for addition of two numbers.
user. Ans: Refer Q. 1.19, Page SQ TE, Unit-1, Two Marks Questions.
entered by the 4-24E, Unit-4.
4.26, Page
Ans. Refer Q. programming.
C c. Define all arithmetic operators.
of structuretoinenter and print the
b. the importance
Explainprogram structure fields Ans: Refer Q. 2.11, Page SQ-10E, Unit-2, Two Marks Questions.
Write a inavailable in your library. Following and
Cusing
record of 10 books : book_title, bookprice d. Explain the need of break in switch statement with
record
may be included in the example.
number_of pages. Ans Refer Q.
3.9, Page SQ-14E, Unit-3, Two Marks Questions.
3-30E, Unit-3.
Ans. Refer Q. 3.35, Page (7x1=7)
: e. Write the syntax of continue statement.
any one part of the following a program in C to
7. Attempt operations in C. Write a file. Ans: Refer Q. 3,12, Page SQ-16E, Unit-3, Two Marks Questions.
a. Define various file number of character in
count and print the
5-26E, Unit-5.
What is the difference between while and do-while loop ?
Page
Ans. Refer Q. 5.25, Ans: Refer Q. 3.2, Page SQ 13E, Unit-3, Two Marks Questions.
following :
b. Explain the g. Difference
between structure and union.
i. Macros Ans; Refer Q. 3.6, Page SQ-14E, Unit-3, Two Marks Questions.
ii. Union
iii, Enumerated data
types
h. Define sorting algorithm with example.
iv. Type
conversion
S Refer Q. 4.15, Page SQ-21E, Unit-4, Two Marks Questions.
5-31E, Unit-5.
Ans.
i. Macros:
Refer Q. 5.29, Page Unit-3. Unit-3.
: Refer Q. 3.36, Page 3-32E,
Q. 3.38, Page
3-35E, Detine preprocessor and its usage in programming.
ii. Union aas
t types : Refer Unit-2. Refer Q. 5.12, Page
SQ26E. Unit-5. Two Marks Questions.
iii. Enumerated data:Refer Q. 2.5, Page 2-6E,
iV. Type
conversion j. Write
the advantage for the use of linked list.
Solving SP-15E (Sem-1& 2)
SP-16E (Sen-1&2)
Programming for Problern
Questions. Solved Paper (Sem-1X2020-21)
SQ-26E, Unit-5, Two Marks
Ang. Refer Q. 5.13, Page
SECTION B

following : (10 x 3=30) Ansi Refer Q. 3.11,


Attempt any three of the
2. programming languages with Page 3-8E, Unít-3.
a. Brief the generations of the b. Write a program
examples. to find the
session (2022-23). number or entered number
Ans. This question is
out of syllabus from Ans Refer Q. 3.6, not.
Page
is palindrome
you mean by operands ?
Discuss the operator 3-5E, Unit-3.
b. What do of all the operators. 6. Attempt any one
part of the following:
precedence and associativity a. Write a program
Ans. Refer Q. 2.13, Page
2-14E, Unit-2.
from the array two find out the odd and even
(10 ×1 = 10)
program to find the Ansi Refer Q. 3.12, elements
? Write a Page 3-9E, and its count. number
c. Define recursive function recursive function. Unit-3.
factorial of a number with
Unit-4.
b. Explain
the selection sort
4-17E, Ans. Refer Q. 4.21, with
Ans. Refer Q. 4.15, Page Page 4-20E, Unit-4. example.
array. Write the program for
d. Write the advantage of using
two matrix elements.
7. Attempt any one
a. Explain part of the following:
matrix multiplication of dynamic memory
Ans. Refer Q. 3.25, Page
3-22E, Unit-3.
example. allocation concept (10%1=10)
copying the Ans. Refer Q. 5.9, Page with proper
e. Explain the handlingand write a program for 5-9E, Unit-5.
another file.
content of one file into Unit-5.
b. Explain the different
type of modes
Ans, Refer Q. 5.22,
Page 5-22E, handling. and I/O function in file
Ans. Refer Q. 5.23, Page
SECTION C 5-23E, Unit-5.
(10.x 1 = 10)
the following:
Attempt any one part
of
(iii)
3.
notes on (i) Compiler (ii) Interpreter
a. Write the short
Linker (iv) Loader.
Ans. Refer Q. 1.16, Page
1-18E, Unit-1.

in C with proper
example.
b. Brief the storage classes
1-39E, Unit-1.
Ans: Refer Q. 1.39, Page
(10 × 1 = 10)
any one part of the following: out of
4 Attempt program to find out the greatest number
a. Write a
three numbers.
Unit-2.
Ans: Refer Q. 2.15, Page 2-16E,
of control
statements used in
b. Explain different type
programming with example.
Unit-2.
Ang Refer Q. 2.29, Page 2-30E, = 10)
(10x 1
5. Attemptany one part the following:
of
pattern :
a. Write a program to print for the
Solving
SP-17E (Sem-1&2) SP-18E (Sem-1& 2)
Progranming for Problem Solved Paper (Sem-2)(2021-22)
Ans. Refer Q. 4.14,
B. Tech. Page SQ-21E, Unit-4, Two
SEMESTER THEORY
) ODD
i. Find the output of
the following code
Marks Questions.
(SEM. EXAMINATION, 2021-22 void mnain()
PROBLEM SOLVING int a,"p;
PROGRAMMNG FOR l value of a is input by
the user and assumed
Max. Marks
: 100 p= &a; it is equal to 7.
scanf(“%d", p);
choose
Time :3 Hours any missing data; then printf(“%od", a);
sections. If require
Note: Attempt all Ans, Refer Q. 2.14, Page
SQ-10E, Unit-2, Two
suitably. Marks Questions.
Section-A j. Explain the significance
(2x 10= 20) Ans. Refer Q. 5.15, Page SQ-26E,of End of File (EOF).
Unit-5, Two Marks
questions in brief: and pseudo
code. Questions.
1. Attempt all between algorithm Questions. SECTION B
a. Differentiate Unit-1, Two Marks
Page SQ-6E,
Refer Q. 1. 16, important? 2. Attempt any
a. Draw block three of the following
Ans. :
Why are they in a
source fle diagram of computer (3 x 10 =30)
b. What
are header files? are text files included a compilation. the components in brief
and explain each of its
Header files file in
files: a header source file.
Ans. Headercompilation. To include Ans. Refer Q. 1.1, Page 1-3E, Unit-1.
must be used in the
during preprocessor directive as they are used
to
#include
: Header files
are important b. Differentiate between type
conversion
Importance
information among
various files. Write aprogram to input a floating pointand typecasting.
number and find
share leftmost digit of integral part of a number.
following code: Ans: Refer Q. 2.8, Page 2-9E, Unit-2.
of the
C. Find the output
void main) C. Write a program to find the sum of series using function
a= 6, z =7, result; 1!+ 2!+3! +4! .....s.....n terms.
+

int x=3, y = 4, + ++a ||lc; Ans: Refer Q. 3.13, Page 3-10E, Unit-3.
y)
result (x>
=

printf("od", result); Questions. d. Write a program to find transpose of matrix.


Unit-2, Two Marks Ans: Refer Q. 3.14, Page 3-10E, Unit-3.
2.20, Page SQ-12E,
Ans: Refer Q. case.
limitations of switchUnit-2, Two Marks
Questions. e. Why are preprocessor required ? Explain any two
d. Write SQ-10E, preprocessor directives.
Q. 2. 12, Page Ans. Refer Q. 5.28, Page
Ans Refer statement. 5-31E, Unit-5.

e Show the
usage of break
SQ-14E, Unit-3, Two Marks
Questions.
. Attempt any one part of the following: (1 x 10 = 10)
3.9, Page variable a. Define flowchart and draw a flowchart to find largest
AAs Refer Q. scope and lifetime ofQuestions. among three numbers.
between Marks
Differentiate Unit-1, Two Ans: Refer Q. 1.22,
Page 1-22E, Unit-1.
t Refer Q. 1.17, Page SQ-6E, array
operator in anQuestions.
Ans. subscript D.
Explain in detail about all storage classes with prope
Marks
limitations of Unit-2, Two complexity. example.
g. Write
Q. 2.13, Page SQ-10E, terms of Ans. Refer Q.
1.39, Page 1-39E, Unit-l.
Ans. Refer
in
and binary search
h. Compare linear
SP-19 E
(Sen-l
Progranmming for Problem Solving
10 10) Solved Paper
any one part the following: operators (1xdetail,
of (Sem-2)/2021-22)
4. Attempt and Bitwise in BTech.
a. Explain Logical, Unary (SEM. II)EVEN
2.2, Page 2-5E, Unit-2. SEMIESTER
Ans. Refer Q. case. Write a menn EXAMINATION, THEORY
Compare if-else-if ladder and switch calculator. PROGRAMMNG 2021-22
b. program to perform basic functions of FOR PROBLEM
driven Unit-2. Time :3 Hours SOLVING
Page 2-25E,
Ans Refer Q. 2.25, (1 x 10 = 10)
following: Max.Marks: 100
any one part of theprogramn to find sum of Fibonacci Note:
5. Attempt a 1. Attempt all Sections.
Define recursion. Write choose suitably. If you require any missing
series using recursion.
4-15E, Unit-4.
data; then
4.14, Page
Ans Refer Q. call by refereneo Section-A
Differentiate between call by value and 1. Attempt
all questions in brief.
b, example. a. Differentiate
with proper 4-12E, Unit-4. between'void and
Ans. Refer Q. 4.16, Page int datatypes. (2x 10= 20)
4.10, Page
Ans: Refer Q. (1 10 10) x = SQ-22E, Unit-4, Two Marks
Questions.
the following: sort on tho b. Draw the Pyramid
Attempt any one part
of
6. technique using bubble structure of memory
Ans Refer Q. 1.2, Page SQ-1E,
sorting
a. Implementsequence 98, 101, 15. hierarchy.
:34, 78, 12, 5, 3, Unit-1,Two Marks Questions.
following Unit-4. C.
4.27, Page 4-25E, Describe the syntax and working
Ans: Refer Q. implement linear Ans: Refer Q. 2.15, Page of Ternary o
operator.
a program to SQ-11E, Ünit-2, Two Marks Questions.
b. What is
searching ? Write
d. Write advantages of
search. 426E, Unit-4. Ans: Refer Q. 2.16, Page switch statement.
4.28, Page SQ-11E, Unit-2, TwoMarks Questions.
Ans: Refer Q. : (1 x 10 = 10)

7. Attempt
any one part of the following
Differentiate
memory allocation.example.
between e #include<stdio.h>
Find the output:
a. Define dynamic proper
() with int main()
malloc () and calloc Unit-5.
Q. 5.14, Page 5-14E,
Refer program to a = 100;
Ans modes. Write a int
different file openingdisplay the number of
lines printf(od\n1,a);
b. Explain any file and printf(«Value is=%d"43, a);
read content that
of
file. return 0;
and words in Unit-5.
5.26, Page 5-27E, Ans: Refer Q.2.17, Page SQ-11E,
Ans: Refer Q. Unit-2, Two Marks Questions.
f. Define function
Ans: Refer Q. 4.2, Page
and its type.
SQ-17E, Unit-4, Two Marks Questions.
g. Find the output:
#include<stdio.hedds'sigs
intmain()
{

nt arr1l10):ash aas
sels
SP-22E (Sem-1&
SP-21 E (Scm-1& 2) 2)
Solving Solved Paper (Sem-2)(2021-22)
Programming for Problem AKE; Refer Q. 5.30, Page
5-33E, Unit-5.
printf(rdn", Ofarr);
return 0; Section-C
Questions. 3. Attompt
Two Marks a. Explainany ono part of the following:
2.18, Page
SQ-12E, Unit-2,
Ans, Refer Q. WVhat is the
complexity the difforent kind (10 % 1 10)
space complexity. programming.
AnE; Refer Q. 1.39,
of storage classes
and in C
h. Define time Qucstions. Page 1-39E, Unit-1.
Two Marks
of bubble sort
?
SQ-22E, Unit-4, b. Draw the
Q. 4.17, Page architecturc of digital
Ans: Refer explain its all components. computer system
: AnE. Refer Q. 1.2, Page and
i. Find the output
#include<stdio.h>
1-5E, Unit-1.
4. Attempt any onc part of
int main() Define the following:
operator
printf(“%d",(void *));
type of operatorsand operands. Discuss about the
(10 × 1 10)
different.
used in programming.
AnE Refer Q. 2.4, Page 2-6E, Unit-2.
return 0; Questions.
Unit-2, Two Marks
,
Page SQ-12E, Vhot is use of break
Ans: Refer Q.
2.19, in switch case ? Write a program
function in dynamic develop a calculator using caso to
requirement of FREE) Ane: Refer Q. 2.24, Page 2-24E, Unit-2. in character format.
j. What is the Questions.,
memory allocation. Unit-5, Two Marks
5.14, Page SQ-26E, 5. Attempt any one part ofthe following:
Ans: Refer Q. a. Write a program (10 × 1 = 10)
Section-B for pattern
: (10 x 3= 30)
any three of the following flowchart and draw
2. Attempt symbols used in number.
a. Describe the various reverse ofa ks

the flw chart to find the Unit-1.


Refer Q. 1.23,
Page 1-23E,
Ang
type conversion and type casting kkk

b. Illustrate the concept of ***k


with program. Unit-2.
2.9,Page 2-9E,
Ans. Refer Q. Ans: Refer Q. 3.16,
Page 3-12E, Unit-3.
the pattern
C. Write a program to print b. Write a program to
recursive function. print the Fibonacci series using
12 Ans: Refer Q. 4.14, Page Take the limit from the user as input.
123 4-15E, Unit-4.
1234
6. Attempt any
123 one part of
12
a. Write a
program thefollowing: (10 x 1 = 10)
example. for the selection sort
1
3.15, Page 3-11E,
Unit-3. AnS Refer Q. 4.21,
and explain it with
Ans Refer Q. program Page
4-20E, Unit-4.
bubble sort concept and write the b. Write
d Explain
Q.4.23, Page 4-21E, Unit-4. example. array
a program
to find the product of
AnE Refer
argument with
Aa Refer Q.and print
3.24. Pagethe output in separate
two 2-dimensional
. Discuss about the command line 3-20E,Unit-3. array.
& 2)
SP-22 (Som-1 &2)
E

Solved Pser (Se2222-22


SP-21E(Sem-1
ASE: Refor Q. 5.30, Pasge 5-33E, Unit-5.
Solving!
I'roblem
Progromming lut Section-C
printfrMialln", 0[nrrb:
Qucstiong. 3. Attompt any ono part
of
the following: (101= 10>
returo 0; Marka a. Explain the different kind of storage classes i C
SQ-121E, Unit-2, Two complexity programming.
)
Q. 2 18, P'age What in the
AKE eter comploxity. Ans: Refer Q. 1.39, Page 1-39E, Unit-1.
spaco Qucstions,
time And Marka b Draw the architecture of digital computer system and
h. Define gort ? SQ-22E, Unit-4, Two components.
explain its all
of bublble
4.17, I'rge Ans: Refer Q. 1.2, Page 1-5E, Unit-1.
ARE. Ilefer 4
outpnt (10 x l= 10)
Fini the
#includle<stlio.h 4. Attempt any one part of the following:
Define operator and operands. Discuss about the different
i. n.

int main) type of operators used in programming.


): Ans: Refer Q. 2.4, Page 2-6E, Unit-2.
printt(al",(voll Qucstions. a program to
relorn 0; Unit-2, Two Marks b. What is use of break in switch case ? Write
P'age SQ-12E, dvnamic a
develop calculator using case in character format.
Q. 2.19, function in Refer Q. 2.24, Page 2-24E, Unit-2.
Ans, lefer FREEO Ans:
requiremcnt of Questions.
Whal ie the
allocation, Two Marks 5. Attempt any one part of the following: (10 x 1 = 10)
J. memory
I'age SQ-26E, Unit-5, a. Write a program for pattern
Q. 5.14,
Ans Refer Section-B
(10x3=30) ****
draw
of the
following: flowchart and
A1tempt any three symbols uscd in numnber.
2 Describe the varioUs the reverse ofa
A. to find
the flaw chart Page 1-23E,
Unit-1.
type casting
Refer Q. 1.23, conversion and
AK concept of type ****

the
Illustrate
b. program.
with Unit-2. Ans: Refer Q. 3.16, Page 3-12E, Unit-3.
Page 2-9E,
ABA Pefer Q. 29,
program to print the pattern D.
Write a program to print the Fibonacci series using
c Write a recursive function. Take the limit from the user as input.
Ans: Refer Q. 4.14, Page 4-15E, Unit-4.
12
122 b Attenpt any one part of the following :
(10 x 1 10)
C Write a program for the selection sort
12 example. and explain it with
12 As Refer Q.
4.21, Pa
Unit-3.
Page 3-11E, progrz
Reler 43.15, the b, Wr
As sort concent and write
habble Tample. Riona!
rlain
SP-24E (Sem-1 & 2)
SP-23E (Scm-1& 2) Solved Paper
Programming for Problem Solving (Sem-1)(2022-23)
following:
(10% 1e 10)
memory with dynamic
(SEM. I) ODD B.Tech.
any one part of the user SEMESTER
7. Attempt program to allocate the
a. Write a Take the input
from the EXAMINATION, THEORY
concept. PROGRAMIMING FORPROBLEM2022-23
memory allocation
sum of all elemnents.
and find the Page 5-14E, Unit-5. SOLVING
Ans: Refer Q.
5. 15, program Time : 3 Hours
handling concept and writeaprint tha
the file to another and Max. Marks:70
b. Discuss about content of one file Note: Attempt all sections.

uantUm
If
to copy the coping elements. suitably. require any missing
count of these 5-23E, Unit-5. data; then choose
5.23, Page
Ans: Refer Q. Section-A
1. Attempt all questions in brief :
Draw memory hierarchical
structure of a computer%7 = 14)
a5a Refer Q. 1.2, Page S-1E, Unit-1,
(2
Two Marks QuestionsSystem.
b.
Explain identifiers and keywords
in C
language.
Ans: Identifiers : An
Aunction, or any
identifier is a name
used to identify a
on identifier other user-deiined item within a program. variable,
consists of a sequence of In c
lowercase), digits, and underscore letters (both uppercase and
characters.
Keywords: Refer Q. 1.34, Page 1-34E, Unit-1.
Differentiate between
implicit and explicit type

Ser
Aaá: Refer Q. 2.3, Page SQ-8E, conversion,
Unit-2, Two Marks Questions.
A
Find the output of following
#include<stdio.h> code written in C-language:
main()

int i=l;
for(;;)
(printf(4%d"i);
if(i=5)
break:

As The provided
condition. code contains
The condition a logical error
=
lnstead of '(i=5)) is
using in the if statement
theequality
wll be assigned operator'=,the assignment operator
of comparing a result, the value of
5 instead As
Compare
complexity.linear seearch it to 5. 'i
Ans
Refer
, and binary
Q.4.14,
Page search in terms of
SQ-21E, Unit-4, Two
Marks Questions.
Programming for Problem Solving
E
SP-25 (Sem-1& 2) SP-26 E (Sem-1&2)
a
f. Define the structure of node in linked
list.
Ang; Algorithm Solved Paper
SQ-15E, Unit-3, Two Marks Questions. : (Sem-1/2022-23)
Ans. Refer Q. 3.11, Page Step 1: Start
Step 2:Read
g. List out various file opening modes. the input
Step 3: Declare number
Ans. Refer Q. 5.23, Page 5-23E,
Unit-5. input to a temp and initialize from the user
Step 4 :Start variable ternpNunthe variable reverse
= num
Section-B rem = numthe while loop until num and assign
% 10 !=0 becomes
reverse*= 10 + false
following : (7x3= 21) ii. num rem
Attempt any three of the an =

2. an algorithm. Write num/10


Step 5 : Check
a. State desirable characteristics of Step 6 :Ifit's if reverse
algorithm to calculate
sum of digits ofa number entered ==
tempNum
Step 7:If not,true then the number
by user. Unit-1. Step 8:Stop the number is a palindrome
ofalgorithm:ReferQ. 1.18, Page 1-19E, is NOT a palindrome
Ans. Characteristics
: Q. 1.19, Page 1-20E, Unit .A Flowchart :
Algorithm Refer
types in terms of
Discuss basic data
b. Define data types in
C. range. Start
memory occupied, format specifier and
Ans. Refer Q. 1.36,
Page 1-36E, Unit-1. Read num
and call by reference
between call by value
C. Differentiate using example. reverse =0
parameter passing mechanisms tempNum num
Page 4-12E, Unit-4.
Ans, Refer Q. 4.10,
size and
multiply two matrices (read
d. Write a program to the keyboard).
num ! =0 No
elements of matrices from
Unit-3.
Page 3-20E, Yes
Ans. Refer Q. 3.24, calloc( ), rem num % 10
memory allocation. Explain suitable
ee Discuss dynamic ) and free( ) functions with reverse* = 10 + rem
num =num /10
malloc(), realloc(
example. Yes
Page 5-13E, Unit-5. reverse=
Ans Refer Q. 5.13, tempNum
Section-C
(7x1=7) Palindrome No

part the following:


computer system with
ne not palindrome
Attempt any one components
of
3. of operating
a. lustrate basic explain various functions of
Also, 1-5E, Stop
block diagram. Q. 1.2,
Page
system in detail. systen : Refer
Components of computer Q.
1.9, Fig. 1.
Ans.
system : Refer Attempt any one
Unit-l. of operating a.
Explain variouspart of the following :
Various functions whether bitwise operators (7x1=7)
Page 1-12E, Unit-1. check example. When precedence in Clanguage with help
a flow chart to not. expression of two operators
and draw palindrome or which is same,
operator willhow associativity helps in identifyingin an
b. Write an algorithn user is an example.
by be evaluated
the number entered first. Illustrate it with
SP-27E (Sem-l &2)
Programming for Problem
Solving SP-28E (Sem-1&2)
Solved Paper (Sem-1)(2022-23)
2-11E, Unit-2.
Refer Q. 2.11, Page Unit-2. inthef(int n1, int n2)|
Ans. Bitwise operator:
: Refer Q. 2.13, Page 2-14E, if (n2 != 0)
Example return hcf(n2,
storage classes in C language else
nl % n2);
b. Illustrate various types of return nl;
with suitable example.
1-39E, Unit-1.
Ans. Refer Q. 1.39, Page
(7x1=
7)

: 6. Attempt any one


any one part of the following pattern : a. Write a program part of the following :
5. Attempt to print the given
a. Write a program inC Ans. Refer Q. 4.23, in C to implement (7x1 =7)
Page 4-21E, Unit-4. bubble sort.
b. Construct a
custoners in astructure to customer'
bank. The data specify data of
number, Name, Balance to be stored is : Account
200customers in in account. Assume
maximum of
Ans. #include <stdio.h> Write a programthe bank.
int main) customers (i.e., in C to find and print all details
Account Number, Name
having balance less of
than Rs. 100. and Balance)
int rows = 5; rows. Ans. #include <stdio.h>
Il first loop to print all struct Customer(

es
for (inti= 0;i<rows; i++){ spaces int accountNumber;
Il inner loop 1 to print white {
char name[50];
= <2 * (rows -i)- 1; j++)
for (int j 0;j
float balance;
printf(“ ";

S
};

I/ inner loop 2 to print star character


*
int main() (
for (int k =0; k< 2 *i+1; k++)
( struct Customer customers(200]:
printf("*); int i, numCustomers;
W Read
the data of customers from user
printf("\n"); printf("Enter the number input
scanf"%d", &numCustomers); of customers:")}
return 0; for (i = 0; i< numCustomers;
printf("\nCustomer %d i++) {
\n,i#1);
printf("Account number:");pdt
Illustrate recursion. Write
a program
in C to find GCD
b. scanf("%d", &customersil.accountNumber);
(Greatest Common Divisor) of
two numbers using
printf("Name:"):
recursion. scanf("%s", customerslilname);
Ans. Recursion: Refer Q. 4.12, Page 4-14E, Unit-4. printf(“Balance: "):
Program:
#include<stdio.h> scanf("%f, &customersli].balance);
inthefintnl, int n2);
intmain(O{ I/ Print details of customers
int nl, n2; printf("\nDetails customers having balance less
Rs. 100:\n"); of than Rs, 100
having balance less
printf(“Enter two positive integers: "); than
scanf("%d %d", &nl, &n2); =
for (i 0; <
printf("G.C.D of od and %d is %d.", nl; n2, hcflnl, n2)};
i numCustomers;
return0;
if (customers[i].balance i++)
< 100)
|
printf(“Account
number: %d\n",
printf(Name: customersli].accountNumber);
%s\n", customersli].name);
Programming for Problem Solving SP-29E (Sem-1&2) SP-30 E (Sem-1& 2)

Solved Paper
printf("Balance: %.2f\n", customersli].balancc); (Sem-2)\(2022-23)
(SEM. II) EVENB.Tech.
SEMESTER
EXAMINATION,
return 0;
PROGRAMMING THEORY
2022-23
following: (7 x1=7)
FOR PROBLEM
Attempt any one partthe SOLVING
of
7. as a Time :3 Hours
a. What is Macro ? Illustrate the working of Macro
suitable
help of
variable and as a function with the Note: 1. Attempt Max. Marks:70
example. all Sections. If you
choose suitably. require any
Ane, Refer Q. 5.29, Page 5-31E, Unit-5. 2 The qucstion paper missing data;
then
operations. Write
program in C to
a
English Language may be answered
b. Discuss variousanfile file and displäy the numbers of English, as per or in the mixed in Hindi Language,
read content of existing convenience. language of
Hindi and
words and lines in that :file.
Refer Q.5:25, Page 5-26E,
Unit-5.
Ans. Various file operations
5.26, Page 5-27D, Unit-5?
Section-A
Program :Refer Q. 1,Attempt all questions
a Differentiate in brief.
between algorithm
Ans: and program. (2 %7= 14)

Series
S.No. Aspect Algorithm
Program
1. Definition A
step-by-step procedure
or set A
of rules to
solve collection
problem or perform ainstructions
a programming
of
written in a
task. language
to be executed by a
computer.
2
Purpose Algorithms are
uséd to Programs are
design solutions and used to
solve exécute specific
problems acomputer or tasks on
conceptually. device.

b. Discuss
Ans: An operating
the functions of an operating
system manages system in brief.
resources, computer
facilitating user interaction hardware and software
It provides essential and efficient task execution.
management, functions like process management,
interface. file system handling, memory
device communication,
and user
G Write the output
of following
asei#include <stdio.h> code :
intmain()
SP-31E (Semn-1& 2)
SP-32E (Sem-1 &2)
Programming for Problem Solving Solved Paper (Sem-2)\2022-23)
=
Flow chart to final
int a =- 10, b 20; the sumn
and average of integers :
Start
if(a > &&b<0)
0

a++;
Assign sum = 0, i=
else if(a<0&& b<0) avg = 0.0
0

a--;
else if(a<0&& b> 0)
take input n as range
b--;
else
b--;
printf("%d\n", a+ b); loop to
check ifi!=n Ture take a int value as
input into
return 0; iis iterable 'num, insert it into array

Ans, 9 false
terms of time update sum as
Compare linear search and binary in Sum = Sum + num
d complexity. Questions. Calculate average as
Two Marks
SQ 21E, Unit-4,
Page avg = sum/n
Ans. Refer Q. 4.14,
structure and union.
e. Differentiate between Two Marks Questions.
SQ-14E, Unit-3, print sûm and avg
Ans. Refer Q. 3.6,Page

you mean by pointer arithimetic ? end


f. What do aríthmetic operations
on
refers to performing programming, pointers
Ans: Pointer arithmetic stored pointers, In Fig. 1.
memory addresses in adding or
Pointer arithmetic involves
store addresses ofvariables.to/fröm pointers to navigate memory Explain recursion in C. Write a program
b.

subtracting integer values factorial of a given number using in C to find the


locations. Ans: Refer Q. 4.15, recursive method.
Page 4-17E, Unit-4.
brief. C Write a program
g. Discuss linked list in in C to reverse a given number N having
SQ-25E, Unit-5, Two Marks Questions. any number
of digits.
Ans Refer Q. 5.9, Page Ans: #include<stdio.h>
Section-B int main() {

(7x3= 21) int num, reversed =0,


:
printf("Enter a number:remainder;
Attempt any three of the following m
2.
a. Explain flow chart and benefits
of using the flow chart scanf("%d", &num); ");
to findthe sum andaverage
programming. Draw aflow chart while (num !=
0){
of n integers. : Refer Q. 1.20. Page 1-20E,
Unit-l. remainder = num
Ans. Flowchart and its benefits reversed =
% 10;
num /= reversed * 10 + remainder;
10;
SP-33 E (Sem-1& 2) SP-34E (Sem-1&2)
Programming for Problemn Solving Solved Paper (Sem-2)(2022-23)
printf("Reversed number: %d\n", reversed): return 0;
return 0; V. strcpy :
#include<stdio.h
in C with suitable #include<string.h>
d. Discuss the following string functions int main() {
code snippet: char sourcel] ="Hello";
i. strrev char destination[20};
ii. strcmp strepy(destination,
iii. strcat source);
printf("Copied string:
iv. strlen return 0; %s\n", destination);
V. stropy
Ans Refer Q. 3.29, Page 3-24E, Unit-3. e. Explain
i. strrev: the process of using
suitable examples. Also fopen()
#includeKstdio.h>
file in C. discuss vnriousfunction in C with
modes of opening
#include<string.h> Ans The fopen() method a
int main(0 World!";
a
in Cis library function
file to perform various
char strll ="Hello, ete. along with oporationg that is used to open a
strrev(str); various modes, If which include reading, writing,
printf(Reversed string: %s\n", str); function opens the tho filo oxists then
Syntax :The syntax particular file cls0 a new the fopen()
return 0; of C fopon() file is croated.

eries
FILE *fopen(const is:
char *filonamo, const
where: char modo);
ii. strcmp:
#include<stdio.hs filenamo:This is ofC string typo
#include<string.h> that is nocdod to bo openod. and nccopts tho name of
mode: This ís also ofCstring typo thefilo
int main()
char strl0="apple"; açcess.A and rofdrg to the fmodé oftho
filo
char str20"banana"; Example? Oponing a file for
int result=stremp(str1, str2); #include<stdio.h> roading ;
return 0; int main() {

FILE file;
iii. strcat char ch;
#include<stdio.h>
file = fopen("examplo.txt,
#inclúde<string.h>
if(file == NULL) "):
int main() {
char strl[50] = "Hello, "; printf("File not found or
couldn't be opencd.\n);
char str20 = "World!"; return 1;
strcat(str l,str2);
printf("Concatenated string: %s\n", strl); while ((ch = fgete(file))
!= EOF)(
return 0: putchar(ch);
:
iv. strlen fclose(file);
#include<stdio.h> return 0;
#include<string.h>
int main(){ Various modes
char str]="Hello, World!"; Page 5-23E, Unit-5.of opening a file in C : Refer Q. 5.23,
int length= strlen(str);
printf"Length of the string: %d \n", length);
Section-C
3 Attempt any one
part of the following:
(7xl=7)
SP-35E (Semn-1&
2) SP-36 E (Sem-1 & 2) Solved Paper (Sem-2\2022-23)
Programming for Problem Solving
b. Explain different types of bitwise operators used in C with
used in including the
C

a. Discuss various storage classesvalue, scope and lifetime. suitable examples. Find the value of following expressions :
details of storage place, default i. 10>>2
1-39E, Unit-1. ii. 20<<2
Ans. Refer Q. 1.39, Page
types used in C with suitable iüi. 25 & 30
b. Discuss various primitive data memory size, format iv. 25|30
examples including their required Ans. Bitwise operators: Refer Q. 2.1, Page 2-2E, Unit-2.
specifier and range. Value of expressions :
1-36E, Unit-1. i. 10 >> 2 (Right Shift):
Ans. Refer Q. 1.36, Page (7x1=7)
any one part of the following: Convert 10 tobinary: 1010
4. Attempt
a program in C to print grades as per following Right shift 2 positions: 0010 (which is 2 in decimal)
a. Write percentage of marks mout of 100: ii. 20 <<2(Left Shift):
criteria for obtained Convert 20 to binary: 10100
Grade
Obtained percent Marks (M) Left shift 2 positions: 1010000 (which is 80 in decimal)
A+ iüi. 25 30(AND):
&

90 <M<100 Convert 25 to binary: 11001


A
80 < Ms 90 Convert 30 to binary: 11110
Perform bitwise AND: 11000 (which is 24 in decimal)
B+
70 < Ms 80% iv. 25 | 30 (OR) :
B Convert 25 to binary: 11001
60 <
Ms 70 Convert 30 to binary: 11110
50 < M< 60 Perform bitwise OR: 11111 (which is 31 in decimal)

MS50 5. Attempt any one part of the following: (7xl=7)


a
a. Differentiate between while and do-while loop. Write
Ans. #include<stdio.h> program in C to print the following pattern:
int main) { A12345
float obtainedMarks; 1234
Input the obtained percentage of marks
/printf"Fnter the obtained percentage marks:); 123
scanf("%, &obtainedMarks); on 12
based the obtained marks
I/ Determine the grade
> obtainedMarks <= 100)
{
Ans: Difference:
if (obtainedMarks 90 && Do While Loop
printf("Grade: A+\n"); S.No. While Loop
> && obtainedMarks <= 90)
{

lelse if(obtainedMarks 80 T'he keyword "do while is used.


1. The Keyword while" is used.
printf("Grade: A\n"); present
if (obtainedMarks>70 &&
obtainedMarks <= 80){ executed The control statementis
else
J
2. The control statement is loop body.
after the
printf("Grade: B+\n): before the loop body.
> && obtainedMarks <= 70){ executes once,
}else if (obtainedMarks 60 executes when the The loop body or
printf("Grade: B\n"); 3. The loop body even if the condition is true
> && obtainedMarks <= 60)I condition becomes true.
Jelse if(obtainedMarks 50 |false.
printf("Grade: C\n"); bottom-up approach.
}else if (obtainedMarks <= 50)
{
approach. It follows a
4. It follows a top-down required.
are always
printf("Grade: F\n"); statements, brackets Brackets
}else { 5. F'or single
printf(Invalid percentage entered. \n"); are not required.

return 0;
SP-37E (Sem-1& 2) SP-38E (Sem-1 & 2)

Programming for Problem Solving Solved Paper (Sem-2/2022-23)


for (int i=0;i< n;
Program : i++)!
printf("%d", arr[i);
#include
int main() printf("\n");
selectionSort(arr, n);
int i, j, n; printf("Sorted array:";,
scanf("%od",&n); for (int i=0;i<n; i++){
for(i = 1; i<= n; i++) printf("%d", arr[i);
{
printf("\n):
for(j = i;j <=n; j++)
return 0:
printf("%d", j);
7. Attempt any one part of the following :
printf("\n'"); Explain static memory allocation (7x1=7)
allocation with suitable examples. and dynamic memory
a program in
C
to multiply two Aa Static memory allocation:Q5.10, Page
b.Explain array in C. Write NxN ánd display it
on console. Example of static memory allocation : 510E,
Unit-5.
matrices, each of orderPage 3 18E, Unit3. #include<stdio.h>
3.22,
Ans: Array : Refer Q. of
order NxN: Refer Q.
3.24.
int globalVariable = 10; |/Global variable
Multiply two matrices each void demoFunction(){
Page 3-20E, Unit-3.
=7) static int staticVariable =5; I/ Static local variable
6.Attempt any one part the
of following:
with suitable
Tx1 int localVariable =7; /Local variable
a. Explain call by value and call by reference printf("Global variable: %d\n", globalVariable):
printf("Static localvariable: %d\n", staticVariable):
example.
Unit-4. printf("LOcal yariable: %d\n", localVariable);
Ans Refer Q. 4.7, Page 8E,
4

globalVariable++;
program in Cfor selection sorting.
b. Discus sorting. Write a staticVariable ++;
Page 4-19E, Uit-4. locàlVariable++;
Ans. Sorting: Refer 4.20 :

Program for selection sorting


#include<stdio.h> int máin()1
void selectionSort(int arr, int n)h demoFunction();
=
for (int i 0;i<né1; it demoFunction();
int minlndex i; { return 0;
for (int j =i+ 1;j<, j++) {

if (arrljl < arr[minndex])


minlndex = j;
Dynamic memory allocation : Q. 5.9, Page 5-9E, Unit-5.
Example of dynamicmemory allocation:Q. 5.15, Page 5-14E,
Unit-5,
int temp= arr(minIndex]: b. Discuss various file handling methods
arr[minlndex] = arr[il; used in C in brief.
arri] = temp; WIite a program in C to some text matter into a file
"example.txt" and then write
console using file read this text matter and display on
Ans: There are handling methods.
int main() {
three main
int arr]= (64, 34, 25, 12, 22, 11, 90); Sequential access methods for file handling:
int n sizeof(arr) / sizeof(arr[0]);
= reading or writing file handling: Sequential access involves
printf("0riginal array: "); beginning to the dataasequentialy, one after another, from
end of fle. This method the
is suitable for scenarios
tnch

Programming for Problem Solving SP-39E (Sem-1&2)


as a text
where files are processed in a linear manner, such reading
file line by line. CAUTION NOTICE
:
Random access allows you to
2. Random access file handling
any position within a file, rather than TO STUDENTS, DEALERS,
read or write data at you need to quickly access SHOPKEEPERS,
seguentially. This method is usefula when COPIERS AND WHOM MAY
specific portions of a file, such
as database file.. IT CONCERN
3. Binary file handling: Binary
file handling deals with reading
can include any type of data, including ORDER OF THE HONBLE
and writing binary data, which REGARDING COPYRIGHTHIGH COURT OF DELHI
files can store data more
structures and complex data types. Binary are not human-readable.
INFRINGEMENT OF
efficient.ly compared to text files, but they QUANTUM BOOKS
:
Program This is to inform students, dealers,
#include<stdio.h>
int main()
{

the general public that Quantumshopkeepers, copiers and


Page Private Limited is
FILE *file; the owner of copyright in the QUANTUM
an example text.n"; series of books.
char text] "Hello, this is w")}
=
file = fopen("example.txt", Any unauthorised copying,
scanning,
if (file == NULL){
\n"); distribution or circulation of the QUANTUM reproduction,
printf("Could notopen the file for writing. copy or books (whether
in soft hard copy) amounts to infringement of the
return1; copyright and trademark rights of Quantum
Page Private
fputs(text, file); Limited, which are civil wrongs as well as criminal offences
fclose(file); with punishment extending toimprisonment.
file = fopen("example. tat", "r");
if (file== NULL)( reading n"); Quantum Page Private Limited has initiated a lawsuit
printf(“Could not open the file for title
Quantum Page Private Limited v. Telegram FZLLC &

return 1; Ors., CS(Comm.) 921/2022 against infringers of th


char ch;
QUANTUM books before the Hon'ble High Court of Delb
while ((ch = fgetc(file)) != EOF) By its order dated December 23, 2022, the Hon'ble Hig
putchar(ch); Court has held that unauthorised reproduction of t
QUANTUM books amounts to copyright infringement a
fclose(file); has directed the removal of infringing copies of
return 0; QUANTUM books from various sources, including Telegr
channels.

Students, dealers, shopkeepers, copiers and the gen


public are hereby cautioned not to carry out
unauthorised copying, scanning, reproduction, distrib
and cireulation of +ho ÔIANTI IM hogks (hether in

You might also like