Quantum PSA
Quantum PSA
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
Errors in Compilation
1-32E to 1-33E
Part-20 :
Standard I0 in C......... 1-34E to 1-35E
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 &
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
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
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
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.
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
:
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
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
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
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 &
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.
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
printf("loop"); Questions-Answers
continue;
Questions
Medium Answer Type
getchar(); Long Answer Type and
return 0;
language
?
C
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
&
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;
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
:
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
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
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).
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
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 {
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 :
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);
Ý
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 :
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");
)
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 */
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.
serie Part-4:
Part-5 :Goto
Part-6:
Part7
Part-8
Use of
and
Break.....
and Continue Statements
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
Fig. 3.2.1.]
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.
a
=i/i+ 1);
Evaluate logical
expression Sum = Sum+ a:
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( ){
else
for(i ÷rows; i 1i) s
number");
printf("n is not a Prime forj =1;js-, ++)
printf("%d",);
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++)
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;
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
printf("\n");
j++)
for(j = 1;j<=
i;
for(int i = 1; i<n; i++)
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 }
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.
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
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 {
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),
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;
for(i
= 0;
i<3; it+) Long Answer Type and Medium Agwer Iype Questions
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++)
{
d2.month) &&
(dl.year == d2.year))
iflalil li] >gr)
printf("\nEqual");
alilli1;
gT = else
row = i; printf("\nUnequal")
col =j;
getch);
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
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
union details
es 1.
3.
4
Enumeration (or enum) is a user-defined
constant2, constant3,
Variables of type enum can be
...
J;
in C.
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.
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;
PART-1|
4UNT Functions
Function : Introduction.
Questions-Answers
Long Answer Type and MediumAnswer
Type Questions
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
%
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 :
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
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
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
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
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
fn)
printf("Input array is \n"); CI8a)
< num; i++)
for (i =0; i
26 54 20 17 77 3144 55 93
77 is largest
26 17
cg(n)t 20 31 44 54|55 77 93 26 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
=
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
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
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
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
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 {
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. {
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
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
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.
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);
)
#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 :
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
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)
Registers
i Memory management
ii. Processor management
Cache ii. Device management
Storage
iv. File management
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
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.
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
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;
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
programming"); putchar(char);
printf("C where, char is a character variable/value.
return 0;
getchar)
:
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.
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);
}
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)
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
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)
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
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>
=
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
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 =
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
};
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
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):
&
return 0;
SP-37E (Sem-1& 2) SP-38E (Sem-1 & 2)
globalVariable++;
program in Cfor selection sorting.
b. Discus sorting. Write a staticVariable ++;
Page 4-19E, Uit-4. locàlVariable++;
Ans. Sorting: Refer 4.20 :