Cqbank 15
Cqbank 15
Cqbank 15
Q1. What is algorithm? Write down the general characteristics of an algorithm and write an
algorithm to print the digits of a number in reverse order.
Ans. Algorithm: An algorithm is a sequence of finite instructions, often used for calculation and data
processing.
An algorithm is a step-by-step method of solving a problem.
An algorithm is a set of instructions designed to perform a specific task.
Characteristics of the algorithm:
1) Finiteness: - an algorithm terminates after a finite numbers of steps.
2) Definiteness: - each step in algorithm is unambiguous. This means that the action specified by the step
cannot be interpreted (explain the meaning of) in multiple ways & can be performed without any
confusion.
3) Input:- an algorithm accepts zero or more inputs
4) Output:- it produces at least one output.
5) Effectiveness:- it consists of basic instructions that are realizable. This means that the instructions can
be performed by using the given inputs in a finite amount of time.
Algorithm to print the digits of a number in reverse order:
Digitsreverse(num)
1. Start.
2. Please enter number.
3. Read num.
4. While (num>0) repeat steps 5,6 and 7 otherwise go to step 8.
5. Do digit =num%10
6. Print digit;
7. Do num= num/10
8. Stop
Q2. What do you understand by flow chart? Draw a flow chart to find maximum of three numbers.
Ans-
Flow chart:
It is very important tool for developing algorithm and program.
It is pictorial representation of step by step solution of a problem. Programmer often uses it as a program
planning tool for visually organizing step necessary to solve a problem.
It uses boxes of different shapes that denote different type of instruction.
While making a flow chart a programmer needs not to pay attention on the elements of the programming
language, he has to pay attention to the logic of solution to the problem
Q3. Define computer. Explain anatomy of computer in detail.
Ans- Computer: Computer is an electronics device that can perform various arithmetic and logical
operations. It can receive data, process it and produce output. It can store large amount of data.
A computer system consists of mainly four basic units; namely input unit, storage unit, central
processing unit and output unit. Central Processing unit further includes Arithmetic logic unit and
control unit, as shown in the figure:
Input Unit: This unit is used for entering data and programs into the computer system by the user for
processing. Input devices are,Keyboard, Mouse, Trackball, Touchpad, Light Pen, Magnetic ink character
recognition (MICR), Optical mark recognition (OMR), Bar code reader.
Memory Unit: The storage unit is used for storing data and instructions before and after processing.
Computer’s memory can be classified into two types; primary memory and secondary memory.
Primary Memory can be further classified as RAM and ROM.
RAM or Random Access Memory is the unit in a computer system. It is the place in a computer where the
operating system, application programs and the data in current use are kept temporarily so that they can
be accessed by the computer’s processor. It is said to be ‘volatile’ since its contents are accessible only as
long as the computer is on. The contents of RAM are no more available once the computer is turned off.
ROM or Read Only Memory is a special type of memory which can only be read and contents of which
are not lost even when the computer is switched off. It typically contains manufacturer’s instructions.
Among other things, ROM also stores an initial program called the ‘bootstrap loader’ whose function is to
start the operation of computer system once the power is turned on.
Secondary Memory
RAM is volatile memory having a limited storage capacity. Secondary/auxiliary memory is storage other
than the RAM. These include devices that are peripheral and are connected and controlled by the
computer to enable permanent storage of programs and data.
Secondary storage devices are of two types; magnetic and optical. Magnetic devices include hard disks
and optical storage devices are CDs, DVDs, Pen drive, Zip drive etc.
Output Unit: The output unit is used for storing the result as output produced by the computer after
processing. Output devices are monitor, printer etc.
CPU: The Central Processing Unit (CPU) takes data and instructions from the storage unit and makes all
sorts of calculations based on the instructions given and the type of data provided. It is then sent back to
the storage unit. CPU includes Arithmetic logic unit (ALU) and control unit (CU)
• Arithmetic Logic Unit: All calculations and comparisons, based on the instructions provided, are
carried out within the ALU. It performs arithmetic functions like addition, subtraction, multiplication,
division and also logical operations like greater than, less than and equal to etc.
• Control Unit: Controlling of all operations like input, processing and output are performed by control
unit. It takes care of step by step processing of all operations inside the computer.
Q4. What do you mean by operating system? Explain various functions of operating system.
Operating System:
It is a software program that acts as an interface between the user and the computer. It is a software
package which allows the computer to function.
It is a program that controls the execution of application programs.
It is an interface between applications and hardware.
Functions:
1. Program creation
2. Program execution
3. Access to Input/Output devices
4. Controlled access to files
5. System access
6. Error detection and response
7. Interpreting the commands
8. Managing peripherals
9. Memory management
10. Processor management
11. Information management
12. Process communication
Q5: Differentiate CUI and GUI.
Ans:
BASIS CLI/CUI GUI
Example of GUI operating system: Windows 98, Windows 7, Windows XP, Windows Vista, Mac OS
etc.
Example of Command Line operating system: DOS, Linux, Unix etc.
Q6. What do you understand by memory hierarchy? Explain each memory in brief.
Register: Registers are located inside the processor. Each register typically holds a word of data (often 32
or 64 bits). CPU instructions instruct the arithmetic and logic unit to perform various calculations or other
operations on this data. Registers are the fastest of all forms of computer data storage.
Cache memory: Cache memory is a very high speed semiconductor memory which can speed up CPU. It
acts as a buffer between the CPU and main memory. It is used to hold those parts of data and program
which are most frequently used by CPU.
Main memory: Primary memory holds only those data and instructions on which computer is currently
working. It has limited capacity and data is lost when power is switched off. It is generally made up of
semiconductor device.. The data and instruction required to be processed reside in main memory. It is
divided into two subcategories RAM and ROM.
Disk cache: A disk cache is a mechanism for improving the time it takes to read from or write to a hard
disk. Today, the disk cache is usually included as part of the hard disk. A disk cache can also be a
specified portion of random access memory (RAM). The disk cache holds data that has recently been read
and, in some cases, adjacent data areas that are likely to be accessed next.
Secondary memory: This type It is slower than main memory. These are used for storing data
permanently. CPU directly does not access these memories instead they are accessed via input-output
routines. Contents of secondary memories are first transferred to main memory, and then CPU can access
it. For example: disk, CD-ROM, DVD etc.
Android: Android is a mobile operating system developed by Google. It is used by several smart phones ,
such as the Motorola Droid, the Samsung Galaxy, and Google's own Nexus One.
The Android operating system (OS) is based on the open Linux kernel. Android is open source, meaning
developers can modify and customize the OS for each phone. Therefore, different Android-based phones
may have different graphical user interfaces GUIs even though they use the same OS.
Android phones typically come with several built-in applications and also support third-party programs.
Developers can create programs for Android using the free Android SDK (Software Developer Kit).
Android programs are written in Java and run through Google's "Davlik" virtual machine, which is
optimized for mobile devices. Users can download Android "apps" from the online Android Market.
The version history of the Android mobile operating system began with the release of the Android beta in
November 2007. The first commercial version, Android 1.0, was released in September 2008. The most
recent major Android update is Android 5.0 "Lollipop", which was released on November 3, 2014. Since
April 2009, Android versions have been developed and released in alphabetical order, beginning with
Android 1.5 "Cupcake"; the earlier versions 1.0 and 1.1 were not released under specific code names:
● Cupcake (1.5)
● Donut (1.6)
● Eclair (2.0–2.1)
● Froyo (2.2–2.2.3)
● Gingerbread (2.3–2.3.7)
● Honeycomb (3.0–3.2.6)
● Ice Cream Sandwich (4.0–4.0.4)
● Jelly Bean (4.1–4.3.1)
● KitKat (4.4–4.4.4, 4.4W–4.4W.2)
● Lollipop (5.0–5.1.1)
Q9. What do you mean by translator? Differentiate compiler and interpreter.
Ans- A translator is a computer program that performs the translation of a program written in a given
programming language into a functionally equivalent program in a different computer language, without
losing the functional or logical structure of the original.
Examples of widely used types of computer languages translators include interpreters, compilers, and
assemblers.
Difference between Compiler and Interpreter
No Compiler Interpreter
1 Compiler Takes Entire program as input Interpreter Takes Single instruction as input .
2 Intermediate Object Code is Generated No Intermediate Object Code is Generated
Conditional Control Statements are Executes
3 Conditional Control Statements are Executes slower
faster
Memory Requirement : More (Since Object
4 Memory Requirement is Less
Code is Generated)
Every time higher level program is converted into
5 Program need not be compiled every time
lower level program
Errors are displayed after entire program is Errors are displayed for every instruction
6
checked interpreted (if any)
7 Example : C Compiler Example : BASIC
Q11. What is programming language? Differentiate high level and low level language.
Ans-
Languages are a means of communication. Communication with computers is carried out through a
language. This language is understood both by user and the machine. Every computer language is bound
by rules known as SYNTAX of that language. The user is bound by that syntax while communicating
with the computer system.
Ans-
Pseudocode is an informal way of programming description that does not require any strict programming
language syntax or underlying technology considerations. It is used for creating an outline or a rough draft
of a program. Pseudocode summarizes a program’s flow, but excludes underlying details. System
designers write pseudocode to ensure that programmers understand a software project's requirements and
align code accordingly.
Advantages of pseudo code:
• Pseudocode is understood by the programmers of all types.
• It enables the programmer to concentrate only on the algorithm part of the code development.
• It cannot be compiled into an executable program.
Example: Average of 10 numbers
Set total = 0
Set I =1
While i is less than or equal to 10
Input the next number
Add the number into the total
I = I +1
Set the average to the total divided by 10
Print the average.
Q17. What is storage class in c? Explain various storage classes in c in detail.
Ans-
A storage class is an attribute that tells us where the variable would be stored, what will be the initial
value of the variable if no value is assigned to that variable, life time of the variable and scope of the
variable.
There are four storage classes in C:
1) Automatic storage class
2) Register storage class
3) Static storage class
4) External storage class
Initial /
Storage Storage
S.No. default Scope Life
Specifier place
value
Documentation section : It consists of a set of comment lines giving the name author date etc. of
program and other details.
Link section: It provides information or instructions to the compiler to link functions from the system
library.
Definition section: It defines all symbolic constants.
Global declaration section: Variables that are declared outside all the functions and are used in more
than one function.
Main function section: This section contains two parts declaration part and execution part.
Subprogram section: It contains all the user defined functions that are called in main functions.
Example:
// Sample of C Program(documentation Section)
#inclufe<stdio.h> // link section
#include<conio.h> // link section
#define pi 3.14 // definition section
int a=10; // global variable declaration
void disp(); // global function declaration
void main() // main function definition
{
float area,r;
printf(“enter radius”);
scanf(“%f”,&r);
area=pi*r*r;
printf(“area=%f”,area);
disp();
getch();
}
void disp() // user defined function definition
{
printf(“hello”);
}
1. Syntax error
2. Run Time error
3. Linker error
4. Logical error
5. Semantic error
Syntax error:
• The errors which arises due to violation of any rule or regulation(syntax) of C language during
the development of program those errors are known as Syntax error.
• Syntax errors are also known as the compilation errors as they occurred at the compilation time,.
These errors are mainly occurred due to the mistakes while typing or do not follow the syntax of
the specified programming language.
Examples:-Missing of semicolon or parenthesis (}) or Displaying the value of a variable without its
declaration while writing the code.
1.If we want to declare the variable of type integer,
int a; // this is the correct form
Int a; // this is an incorrect form. .
2. #include <stdio.h>
int main()
{
a = 10; // a is not declared
printf("The value of a is : %d", a);
return 0;
}
3. #include <stdio.h>
int main()
{
int a=2;
if(.) // syntax error we put the (.) instead of condition in 'if', so this generates the syntax error
printf("a is greater than 1");
return 0;
}
Runtime error: The error which occurs during the execution of program those errors are turn termed as
runtime error. The division by zero is the common example of the run-time error. These errors are very
difficult to find, as the compiler does not point to these errors.
Linker error
• Linker errors are mainly generated when the executable file of the program is not created.
• This can be happened either due to the wrong function prototyping or usage of the wrong header
file.
Example1: The most common linker error that occurs is that we use Main() instead of main().
Example2: Using print() instead of printf().
Logical error : The errors which are introduced due to usage of wrong expression formula for logic in
program these errors are called as logical error.
The logical error is an error that leads to an undesired output.
For example using 2 * 3.14 *r as area of circle.
Or by mistake semi colon after for statements.
for(i=0;i<10;i++);
printf(”hello”);
semantic error: This error occurs when a statement is syntactically valid, but does not do
what the programmer intended.
The following can be the cases for the semantic error:
1.Use of a un-initialized variable.
int i;
i=i+2;
2.Type compatibility
int b = "MIET";
3.Errors in expressions
int a, b;
b = a+”hi” ;
4.Array index out of bound
int a[10];
a[10] = 34;
Q21. What is data type in c? Explain basic data type in term of range, format specifier and size?
Ans-Data Type:
A Data Type is a Type of Data.
Data Type is a Data Storage Format that can contain a Specific Type or Range of Values.
When computer programs store data in variables, each variable must be assigned a specific data
type.
C support three classes of data types
1)Primary data type🡪 char, int, float
2) Derived data type🡪 array, pointer
3)User defined data type 🡪 structure, union,enum
Basic data type in C:
Data Type Range Bytes Format
signed char -128 to + 127 1 %c
unsigned char 0 to 255 1 %c
short signed int -32768 to +32767 2 %d
short unsigned int 0 to 65535 2 %u
signed int -32768 to +32767 2 %d
unsigned int 0 to 65535 2 %u
long signed int -2147483648 to 4 %ld
+2147483647
long unsigned int 0 to 4294967295 4 %lu
Float -3.4e38 to +3.4e38 4 %f
double -1.7e308 to +1.7e308 8 %lf
long double -1.7e4932 to +1.7e4932 10 %Lf
Note: The sizes and ranges of int, short and long are compiler dependent. Sizes
in this figure are for 16-bit compiler.
UNIT-2:
Arithmetic Operators:
Operator Description
+ Adds two operands
- Subtracts second operand from the first
* Multiply both operands
/ Divide numerator by denumerator
% Modulus Operator and remainder of after an
integer division
++ Increment operator, increases integer value by
one
-- Decrement operator, decreases integer value
by one
Bitwise Operators:
Bitwise operator works on bits and perform bit by bit operation and used with integer only.
Operator Description
& Binary AND Operator copies a bit to the
result if it exists in both operands.
| Binary OR Operator copies a bit if it exists in
eather operand.
^ Binary XOR Operator copies the bit if it is set
in one operand but not both.
~ Binary Ones Complement Operator is unary
and has the efect of 'flipping' bits.
<< Binary Left Shift Operator. The left operands
value is moved left by the number of bits
specified by the right operand.
>> Binary Right Shift Operator. The left
operands value is moved right by the number
of bits specified by the right operand.
Assignment Operators:
Operator Description
= Simple assignment operator, Assigns
values from right side operands to left
side operand
+= Add AND assignment operator, It adds
right operand to the left operand and
assign the result to left operand
-= Subtract AND assignment operator, It
subtracts right operand from the left
operand and assign the result to left
operand
*= Multiply AND assignment operator, It
multiplies right operand with the left
operand and assign the result to left
operand
/= Divide AND assignment operator, It
divides left operand with the right
operand and assign the result to left
operand
%= Modulus AND assignment operator, It
takes modulus using two operands and
assign the result to left operand
<<= Left shift AND assignment operator
>>= Right shift AND assignment operator
&= Bitwise AND assignment operator
^= bitwise exclusive OR and assignment
operator
|= bitwise inclusive OR and assignment
operator
Misc Operators
Operator Description
sizeof() Returns the size of an variable.
& Returns the address of an variable.
* Pointer to a variable.
?: Conditional Expression
Q2. What do you mean by ternary operator in c? Write a program to find the largest of three
numbers using ternary operator.
Ans- Ternary Operator: In C programming language the operator which takes THREE arguments
(operands) is called as Ternary Operator. The "Conditional Operator" ( ? : ) is called as "Ternary
Operator" in C Language, because this operator takes three operands.
Syntax: condition ? Expression_1 : Expression_2 ;
Here, if the given condition is TRUE then Expression_1 is performed, if the condition is FALSE
then Expression_2 is preformed.
Program to find largest of three using ternary operator :
# include <stdio.h>
# include <conio.h>
void main()
{
int a, b, c, big ;
clrscr() ;
printf("Enter three numbers : ") ;
scanf("%d %d %d", &a, &b, &c) ;
big = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c) ;
printf("\nThe biggest number is : %d", big) ;
getch() ;
}
Output of above program
Enter three numbers : 20 30 10
The biggest number is : 30
| Bitwise OR
^ Bitwise exclusive OR
~ Bitwise complement
Operators Meaning of operators
Bitwise OR operator in C
The output of bitwise OR is 1 if either of the bit is 1 or both the bits are 1. In C Programming, bitwise OR
operator is denoted by |.
12 = 00001100 (In Binary)
25 = 00011001 (In Binary)
Q6. What do understand by type conversion? Explain implicit and explicit type conversion with
example.
Ans- Type conversion: Conversion of one data type from another data type is called type casting.
Conversion between data types can be done in two ways :
● Implicit conversion
● Explicit conversion g
Implicit conversion:
Implicit conversion doesn't require a casting operator. This casting is normally used when converting data
from smaller integral types to larger or derived types to the basic type. Implicit Type Conversion also
known as Widening.
int x = 123;
double y = x;
In the above statement, the conversion of data from int to double is done implicitly, in other words
programmer don't need to specify any type operators.
Explicit conversion: Explicit conversion requires a casting operator. This conversion is normally used
when converting a double to int or a base type to a derived type. The Explicit type Conversion is also
known as borrowing.
double y = 123;
int x = (int)y;
In the above statement, we have to specify the type operator (int) when converting from double to int
else the compiler will throw an error.
Q7. Define sizeof() operator with example. Differentiate pre and post increment.
Ans- sizeof() operator
1. sizeof() operator is used to calcualte the size of data type or variables.
2. sizeof() operator will return the size in integer format.
3. sizeof() operator syntax looks more like a function but it is considered as an operator in c
programming
Example of sizeof() operator :
#include<stdio.h>
#include<conio.h>
void main()
{
int ivar;
char cvar;
float fvar;
clrscr();
printf("%d", sizeof(ivar));
printf("%d", sizeof(cvar));
printf("%d", sizeof(fvar));
return 0;
}
Syntax:
if (condition)
{
Statements;
}
2. If-else statement: Here, we have two block of statements. If condition results true then if block
gets execution otherwise statements in else block executes. else cannot exist without if statement.
Syntax:
if (condition)
{
Statements;
}
else
{
Statements;
}
3. Switch-case statement: This is very useful when we have several blocks of statements, which
requires execution based on the output of an expression or condition. Switch defines an
expression (or condition) and case has a block of statements, based on the result of expression,
corresponding case gets execution. A switch can have any number of cases; however there should
be only one default handler.
switch (n)
{
case constant1:
code/s to be executed if n equals to constant1;
break;
case constant2:
code/s to be executed if n equals to constant2;
break;
.
.
default:
code/s to be executed if n doesn't match to any cases;
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("enter number");
scanf("%d",&n);
if(n%2==0)
printf("%d is EVEN\n",n);
else
printf("%d is ODD ",n);
getch();
}
Q9. What is the importance of switch case in c. Write a menu driven program to add, subtract,
multiply and divide two numbers.
Ans-
Decision making are needed when, the program encounters the situation to choose a particular statement
among many statements. If a programmer has to choose one block of statement among many alternatives,
nested if-else can be used but, this makes programming logic complex. This type of problem can be
handled in C programming using switch statement.
Syntax of switch-case
switch (n)
{
case constant1:
code/s to be executed if n equals to constant1;
break;
case constant2:
code/s to be executed if n equals to constant2;
break;
.
.
.
default:
code/s to be executed if n doesn't match to any cases;
}
The value of n is either an integer or a character in above syntax. If the value of n matches constant
in case, the relevant codes are executed and control moves out of the switch statement. If the ndoesn't
matches any of the constant in case, then the default codes are executed and control moves out
of switch statement.
The break statement at the end of each case cause switch statement to exit. If break statement is not used,
all statements below that case statement are also executed.
/* C Program to create a simple calculator for addition, subtraction,
multiplication and division */
#include<conio.h>
# include <stdio.h>
void main()
{
char o;
float num1,num2;
printf("Select an operator either + or - or * or / \n");
fflush(stdin);
scanf("%c",&o);
printf("Enter two operands: ");
scanf("%f%f",&num1,&num2);
switch(o)
{
case '+':
printf("%f + %f = %f",num1, num2, num1+num2);
break;
case '-':
printf("%f - %f = %f",num1, num2, num1-num2);
break;
case '*':
printf("%f * %f = %f",num1, num2, num1*num2);
break;
case '/':
printf("%f / %f = %f",num1, num2, num1/num2);
break;
default:
/* If operator is other than +, -, * or /, error message is shown */
printf("Error! operator is not correct");
break;
}
getch();
}
Q10. What do you understand by else if ladder? Write a program to find largest of three numbers.
Ans- In C programming language the else if ladder is a way of putting multiple ifs together when
multipath decisions are involved. It is a one of the types of decision making and branching statements. A
multipath decision is a chain of if’s in which the statement associated with each else is an if. The general
form of else if ladder is as follows -
if ( condition 1)
{
statement - 1;
}
else if (condtion 2)
{
statement - 2;
}
else if ( condition n)
{
statement - n;
}
else
{
default statment;
}
statement-x;
This construct is known as the else if ladder. The conditions are evaluated from the top of the ladder to
downwards. As soon as a true condition is found, the statement associated with it is executed and the
control is transferred to the statement-x (skipping the rest of the ladder). When all the n conditions
become false, then the final else containing the default statement will be executed.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("\n enter three no.");
scanf("%d%d%d",&a,&b,&c);
if(a>=b)
{if(a>=c)
printf("%d is largest",a);
else
printf("%d is largest",a);
}
else
{
if(b>=c)
printf("%d is largest",a);
else
printf("%d is largest",a);
}
getch();
}
Q11. Differentiate conditional operator and if else . Write a program to check whether a given year
is leap year or not.
Ans-
If else Conditional operator
In if else statement else is optional Both expr2 and expr3 are needed.
N statement can be written within if and else 1 statement can be written within exp2 and expr3
block. block.
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("enter year");
scanf("%d",&n);
if(n%100==0)
{
if(n%400==0)
printf("%d is LEAP YEAR\n",n);
else
printf("%d is NOT LEAP YEAR ",n);
}
else
{
if(n%4==0)
printf("%d is LEAP YEAR\n",n);
else
printf("%d is NOT LEAP YEAR ",n);
}
getch();
}
Q12. Differentiate switch case and if else.
Ans:
If else switch
All data types are permit able in condition Float value is not allowed as case label.
Unit:3
Ans- Iteration, in the context of computer programming, is a process wherein a set of instructions or
structures are repeated in a sequence a specified number of times or until a condition is met. When the
first set of instructions is executed again, it is called iteration. When a sequence of instructions is executed
in a repeated manner, it is called a loop.
There are following differences between while and do-while:
Sr.N. do while While
1. do -while loop runs at least once even while loop do not run in case the condition given is
though the the condition given is false false
2. In a do-while loop the condition is In a while loop the condition is first tested and if it
tested at the last. returns true then it goes in the loop.
3. do while is exit control loop. While loop is entry control loop
4. Syntax do while loop : Syntax while loop:
do while (condition)
{ {
Statements; Statements;
}while(condition); }
Q3. Explain various loop control structure in detail.
Ans-L oops cause program to execute the certain block of code repeatedly until test condition is false.
Loops are used in performing repetitive task in programming. Consider these scenarios:
● You want to execute some code/s 100 times.
● You want to execute some code/s certain number of times depending upon input from user.
These types of task can be solved in programming using loops. There are 3 types of loops in C
programming:
I. for loop II. while loop III. do...while loop
Initialization;
do {
some code/s;
{
printf("*");
}
printf("\n");
}
getch();
}
Q11. What do you understand by function? Write a program to calculate ab using function (without
using library function pow()).
Ans-
Function in programming is a segment that groups a number of program statements to perform specific
task. A C program has at least one function main( ). Without main() function, there is technically no C
program.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,r;
int power(int,int);
clrscr();
printf("enter number and its power\n");
scanf("%d%d",&a,&b);
r=power(a,b);
printf("result=%d\t",r);
getch();
}
int power(int m,int n)
{
int i,p=1;
for(i=1;i<=n;i++)
p=p*m;
return(p);
}
Q12. What do mean by library function. Explain four type of user defined function with example.
Ans- Library function:
● Library functions in C language are inbuilt functions which are grouped together and placed in a
common place called library.
● Each library function in C performs specific operation.
● We can make use of these library functions to get the pre-defined output instead of writing our
own code to get those outputs.
● These library functions are created by the persons who designed and created C compilers.
● All C standard library functions are declared in many header files which are saved as file_name.h.
User defined Function: These function are created by user as per his need.
Type of user defined function:
1. No argument no return value
void add(void);
2. With argument but no return value
void add(int,int);
3. No argument with return value
int add(void);
4. With argument with return value
int add(int,int);
Q13. What is recursive function? Write a program to calculate factorial of a number using
recursion.
Recursive Function: Recursive function is the function which calls itself repeatedly until some condition
is met and then the function stops calling itself and returns to the caller.
A recursive function has two parts:
1- Base case (stopping condition)
2-Recursive case :which must always get closer to base case from one invocation to another.
/*program to calculate factorial using recursive function*/
#include<stdio.h>
int fact(int);
int main(){
int num,f;
printf("\nEnter a number: ");
scanf("%d",&num);
f=fact(num);
printf("\nFactorial of %d is: %d",num,f);
return 0;
}
Q14. Differentiate iteration and recursion. Write a recursive program to find GCD(greatest
common divisor) of two numbers.
Ans- Difference between Recursion and Iteration
RECURSION ITERATIONS
Recursive function – is a function that is partially Iterative Instructions –are loop based
defined by itself repetitions of a process
not reduce the problem in a manner that converges loop-condition test never becomes false
Recursion terminates when a base case is recognized It terminates when the loop-condition fails
Recursion is usually slower then iteration due to Iteration does not use stack so it's faster than
Recursion uses more memory than iteration Iteration consume less memory
Infinite recursion can crash the system infinite looping uses CPU cycles repeatedly
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,r;
int gcd(int,int); //Function prototype
clrscr();
printf("enter two numbers\n");
scanf("%d%d",&a,&b);
if(a>b)
r=gcd(a,b);
else
r=gcd(b,a);
printf("result=%d\t",r);
getch();
}
int gcd(int m,int n)
{
if(n==0)
return(m);
else
return(gcd(n,m%n));
}
Q15. What is function prototyping? Write a recursive program to print n terms of Fibonacci series.
Ans- Function Prototype: All identifiers in C need to be declared before they are used. This is true for
functions as well as variables. For functions the declaration needs to be before the first call of the
function. A full declaration includes the return type and the number and type of the arguments. This is
also called the function prototype.
Recursive program in c to print n Fibonacci terms :
#include<stdio.h>
#include<conio.h>
void main()
{
int n,f,i;
int fib(int); //Function prototype
clrscr();
printf("enter how many terms\n");
scanf("%d",&n);
printf("\n Fibonacce series is as follows:\n");
for(i=0;i<n;i++)
{
f=fib(i);
printf("%d\t",f);
}
getch();
}
int fib(int a)
{
if(a==1||a==0)
return(a);
else
return(fib(a-1)+fib(a-2));
}
Q16- Define argument and also differentiate actual and formal argument.
Ans: It is possible to pass data to the functions as inputs. They are known as arguments. The two
common terms that are related to functions are Actual arguments and Formal arguments.
The Actual parameters are the The Formal Parameters are the variables defined by
values that are passed to the the function that receives actual values when the
function when it is invoked. function is called.
main()
int add(int d,int e)//d,e are formal parameter
{
{
add(a,b); //a and b are actual
return(d+e);
parameter
}
}
1 A copy of value is passed to the function An address of value is passed to the function
2 Changes made inside the function is not Changes made inside the function is reflected
reflected on other functions outside the function also
3 Actual and formal arguments will be created Actual and formal arguments will be created
in different memory location in same memory location
5. void swap(int,int);// function declaration void swap(int *,int *);// function declaration
swap(a,b);// function calling swap(&a,&b);// function calling
//function definition //function definition
void swap(int c,int d) void swap(int *c,int *d)
{ {
int t; int t;
t=c; t=*c;
c=d; *c=*d;
d=t; *d=t;
} }
Q18. What is pointer? Write a program to swap two numbers using call by reference.
Ans-
Pointer-A pointer is a variable whose value is the address of another variable, i.e., direct address of the
memory location. Like any variable or constant, you must declare a pointer before you can use it to store
any variable address.
The general form of a pointer variable declaration is:
type *var-name;
example- int *p; here p is a pointer which stores the address of an integer variable.
// WAP to to swap two numbers using call by reference
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
void swap(int *,int *);
clrscr();
printf("enter first no.");
scanf("%d",&a);
printf("enter second no.");
scanf("%d",&b);
printf("before swapping =%d b=%d\n",a,b);
swap(&a,&b);
printf("\nafter swapping in main a=%d b=%d ",a,b);
getch();
}
void swap(int *p,int *q)
{
int c;
c=*p;
*p=*q;
*q=c;
printf("after swapping in swap a=%d b=%d ",*p,*q);
}
Q19. What is double pointer? Write a program to calculate area and perimeter of a circle using
pointer.
Ans-
Pointer Stores the address of the Variable. Double Pointer Stores the address of the Pointer Variable.
Double (**) is used to denote the double Pointer.
Exp:
int num = 45 , *ptr , **ptr2 ;
ptr = #
ptr2 = &ptr;
Statement What will be the Output ?
*ptr 45
**ptr2 45
Ptr &num
ptr2 &ptr
// WAP to calculate area and perimeter of a circle using pointer.
#include<stdio.h>
#include<conio.h>
void main()
{
int r;
float area,peri;
void cal(int *,float *,float *);
clrscr();
printf("enter radius of circle");
scanf("%d",&r);
cal(r,&area,&peri);
printf("\narea of circle=%f and perimeter=%f",area,peri);
getch();
}
void cal(int *a,float *b,float *c)
{
*b=3.14*(*a)*(*a);
*c=2*3.14*(*a);
}
Extra Important programs:
1. WAP to check entered number is palindrome or not.
2. WAP to print all prime number between 100 to 500
3. WAP using recursion to find ab.
UNIT-4
Q1. Define array. Write a program to search an element in array.
Ans- Array:
● An array is a collection of similar data type elements stored in contiguous memory locations.
● An array is also termed as subscript variable. Here first element is stored as 0th location.
● Till the array is not initialized it contains garbage value while if partially initialized it contains
zero.
● One of the limitation of array is, it does not provide bound checking.
● Array name is base address of array (base address is the address of first element of array). And
You cannot change the base address of array.
Application of Array
Searching- It is the process of finding the location of specific element in an array of n elements. e.g.
linear search, binary search
Sorting- It is the process of arranging the elements in specific order in an array of n elements. e.g. bubble
sort
Example for C Arrays:
● int a[10]; // integer array
● char b[10]; // character array
// WAP to search an element in one dimensional array
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100];
int i,num,pos,c=0,n;
clrscr();
printf("enter size of array");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter value");
scanf("%d",&a[i]);
}
printf("enter number which you want to search");
scanf("%d",&num);
for(i=0;i<n;i++)
{
if(num==a[i])
{
printf("%d is found at a[%d]\n",num,i);
c++;
}
}
if(c==0)
printf("%d in not present in array");
else
printf("%d is fount %d times in array",num,c);
getch();
}
Q2. How will you declare 3D array? Write a program to find largest element of 1D array.
Ans- Declaration of 3D array is follow:
int a[3][4][3];
// WAP to find largest element in one dimensional array
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100];
int i,lar,n;
clrscr();
printf("enter size of array");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter value");
scanf("%d",&a[i]);
}
lar=a[0];
for(i=0;i<n;i++)
{
if(a[i]>lar)
lar=a[i]
}
printf("%d is largest",lar);
getch();
}
Q3. What is 2D array? Write a program to find sum of all elements of 2D array.
Ans- Two dimensional array in C:
● Two dimensional array is nothing but array of array.
● syntax : data_type array_name[num_of_rows][num_of_column]
S.no Array declaration Array initialization Accessing array
Syntax: data_type arr_name data_type arr_name[2][2] =
1 arr_name[index];
[num_of_rows][num_of_column]; {{0,0},{0,1},{1,0},{1,1}};
arr [0] [0] = 1; arr [0]
]1] = 2;arr [1][0] = 3;
2 Example:int arr[2][2]; int arr[2][2] = {1,2, 3, 4};
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],i,j,m,n,s=0;
clrscr();
printf("enter the order of matrix");
scanf("%d%d",&m,&n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("enter matrix");
scanf("%d",&a[i][j]);
s=s+a[i][j];
}
}
printf("\nsum=%d",s);
getch();
}
Q4. Write a program to multiply two matrices.
Ans-
// WAP to multiply two matrices
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5][5],b[5][5],c[5][5],i,j,k,m,n,p,q;
clrscr();
printf("enter the order of First matrix");
scanf("%d%d",&m,&n);
printf("enter the order of Second matrix");
scanf("%d%d",&p,&q);
if(n!=p)
{
printf("Multiplication Not possible");
}
else {
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
printf("enter First matrix");
scanf("%d",&a[i][j]);
}
for(i=0;i<p;i++)
for(j=0;j<q;j++)
{
printf("\nenter Second matrix");
scanf("%d",&b[i][j]);
}
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{ c[i][j]=0;
for(k=0;k<n;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
}
getch();
}
Q5. What is sorting? Write a program to sort n numbers.
Ans- Sorting: Sorting is a process through which the data is arranged in ascending or descending order.
Sorting can be classified in two types;
Internal Sorts:- This method uses only the primary memory during sorting process. All data items are
held in main memory and no secondary memory is required this sorting process.
Example: Selection sort Heap Sort, Insertion sort, Bubble Sort , Quick sort
External Sorts:- Sorting large amount of data requires external or secondary memory. This process uses
external memory such as HDD, to store the data which is not fit into the main memory.
Example:- Merge Sort
// program to sort n numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,t,a[25],n;
clrscr();
printf("how many elements");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter value");
scanf("%d",&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
printf("\nsorted array is \n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
getch();
}
Structure Union
1.The keyword struct is used to define a structure 1. The keyword union is used to define a union.
2. When a variable is associated with a structure, 2. When a variable is associated with a union, the
the compiler allocates the memory for each compiler allocates the memory by considering the
member. The size of structure is greater than or size of the largest memory. So, size of union is
equal to the sum of sizes of its members. The equal to the size of largest member.
smaller members may end with unused slack bytes.
3. Each member within a structure is assigned 3. Memory allocated is shared by individual
unique storage area of location. members of union.
4. The address of each member will be in 4. The address is same for all the members of a
ascending order This indicates that memory for union. This indicates that every member begins at
each member will start at different offset values. the same offset value.
5 Altering the value of a member will not affect 5. Altering the value of any of the member will
other members of the structure. alter other member values.
6. Individual member can be accessed at a time 6. Only one member can be accessed at a time.
7. Several members of a structure can initialize at 7. Only the first member of a union can be
once. initialized.
Q9. What is union? Write a program to print the record of student having maximum marks.
Structure student has following fields: Integer roll number, string student name, string class name,
integer marks.
Ans- A union is a special data type available in C that enables you to store different data types in the
same memory location. You can define a union with many members, but only one member can contain a
value at any given time. Unions provide an efficient way of using the same memory location for
multi-purpose.
Defining a Union: To define a union, you must use the union statement. Here is the way you would
define a union type named Data which has the three members i, f, and str. The format of the union
statement is as follows:
union Data
{
int i;
float f;
char str[20];
} data;
Now, a variable of Data type can store an integer, a floating-point number, or a string of characters. The
memory occupied by a union will be large enough to hold the largest member of the union. For example,
in above example Data type will occupy 20 bytes of memory space because this is the maximum space
which can be occupied by character string.
Q10. Differentiate array and structure. Write a program to print the names of player whose batting
average is greater than 50.Fields of structure (cricket) is name of player, name of country and
batting average of player.
Ans-
Array Structure
i. Data Collection
Array elements are referred by subscript. Structure elements are referred by its unique name.
Array elements are accessed by it's position or Structure elements are accessed by its object as '.'
subscript. operator.
v. Syntax
struct struct_name
{
structure element 1;
structure element 2;
<data_type> array_name[size];
----------
----------
structure element n;
}struct_var_nm;
vi. Example
struct student
{
int abc[5]; int rollno;
char name[50];
}it;
// program to print name of player having batting average more than 50.
#include<stdio.h>
#include<conio.h>
struct cricket
{
float batting_average;
char player_name[20];
char country_name[20];
};
void main()
{
struct cricket c[50];
int i;
clrscr();
for(i=0;i<50;i++)
{
printf("enter batting average,name of player and name of country");
scanf("%f%s%s",&c[i].batting_average,&c[i].player_name,&c[i].country_name);
}
printf("\n Name of players who have batting average more than 50\n");
printf("\nPlayer Name\n");
for(i=0;i<50;i++)
{
if((c[i].batting_average)>50)
printf("\n%s",c[i].player_name);
}
getch();
}
Q11. Write sort notes on enum.
Ans-
An enumeration is a user-defined data type consists of integral constants and each integral constant is
given a name. Keyword enum is used to define enumerated data type.
enum type_name{ value1, value2,..., valueN };
Here, type_name is the name of enumerated data type or tag. And value1, value2,....,valueN are values of
type type_name.
By default, value1 will be equal to 0, value2 will be 1 and so on but, the programmer can change the
default value as below:
enum suit
{
club=0;
diamonds=10;
hearts=20;
spades=3;
};
Q13. What is the importance of ‘\0’ in string? Write a program to concatenate two strings.
Ans-
In C, a string is a one-dimensional array of characters terminated a null character(‘\0’). The terminating
null character is important. In fact, a string not terminated by ‘\0’ is not really a string, but merely a
collection of characters.
Program for concatenate two strings using pointers:
#include<conio.h>
#include<stdio.h>
void main()
{
char str1[50],str2[20];
void strcon(char [],char []);
clrscr();
puts("enter string");
gets(str1);
printf("enter second string");
gets(str2);
strcon(str1,str2);
printf("after concatenate string is\n");
puts(str1);
getch();
}
void strcon(char *p,char *q)
{
while(*p!='\0')
p++;
while(*q!='\0')
{
*p=*q;
p++;
q++;
}
*p='\0';
}
UNIT-5
Allocates requested size of bytes and returns a pointer first byte of allocated
malloc()
space
Allocates space for an array elements, initializes to zero and then returns a
calloc()
pointer to memory
malloc()
The name malloc stands for "memory allocation". The function malloc() reserves a block of memory of
specified size and return a pointer of type void which can be casted into pointer of any form.
Syntax of malloc()
ptr=(cast-type*)malloc(byte-size)
Here, ptr is pointer of cast-type. The malloc() function returns a pointer to an area of memory with size of
byte size. If the space is insufficient, allocation fails and returns NULL pointer.
ptr=(int*)malloc(100*sizeof(int));
This statement will allocate either 200 or 400 according to size of int 2 or 4 bytes respectively and the
pointer points to the address of first byte of memory.
calloc()
The name calloc stands for "contiguous allocation". The only difference between malloc() and calloc() is
that, malloc() allocates single block of memory whereas calloc() allocates multiple blocks of memory
each of same size and sets all bytes to zero.
Syntax of calloc()
ptr=(cast-type*)calloc(n,element-size);
This statement will allocate contiguous space in memory for an array of n elements. For example:
ptr=(float*)calloc(25,sizeof(float));
This statement allocates contiguous space in memory for an array of 25 elements each of size of float, i.e,
4 bytes.
free()
Dynamically allocated memory with either calloc() or malloc() does not get return on its own. The
programmer must use free() explicitly to release space.
syntax of free()
free(ptr);
This statement cause the space in memory pointer by ptr to be deallocated.
realloc()
If the previously allocated memory is insufficient or more than sufficient. Then, you can change memory
size previously allocated using realloc().
Syntax of realloc()
ptr=realloc(ptr,newsize);
Here, ptr is reallocated with size of newsize.
Q2. Differentiate calloc() and malloc().Write a program to find sum of n integer numbers using
dynamic memory allocation.
Ans
malloc calloc
The name malloc stands for memory allocation. The name calloc stands for contiguous
allocation.
malloc() takes one argument that is, number of calloc() take two arguments those are: number
bytes. of blocks and size of each block.
malloc is faster than calloc. calloc takes little longer than mallocbecause of
the extra step of initializing the allocated
memory by zero.
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
void main()
{
int n,i,*ptr,sum=0;
printf("Enter number of elements: ");
scanf("%d",&n);
ptr=(int*)calloc(n,sizeof(int));// ptr=(int*)malloc(n*sizeof(int));
if(ptr==NULL)
{
printf("Error! memory not allocated.");
exit(0);
}
printf("Enter elements of array: ");
for(i=0;i<n;++i)
{
scanf("%d",ptr+i);
sum=sum + *(ptr+i);
}
printf("Sum=%d",sum);
free(ptr);
getch();
}
Q3. What do you understand by file handling? Write a program to copy contents of one file to
another file.
Ans- A file represents a sequence of bytes on the disk where a group of related data is stored. File
is created for permanent storage of data. FILE is inbuilt structure in c.
In C language, we use a structure pointer of FILE type to declare a file.
FILE *fp;
C provides a number of functions that helps to perform basic file operations like create, delete,
open, close, modify etc. Following are some functions:
Function description
fopen() create a new file or open a existing file
fclose() closes a file
getc() reads a character from a file
putc() writes a character to a file
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp1,*fp2;
char ch,fname1[20],fname2[20];
printf("\n enter sourse file name");
gets(fname1);
printf("\n enter sourse file name");
gets(fname2);
fp1=fopen(fname1,"r");
fp2=fopen(fname2,"w");
if(fp1==NULL||fp2==NULL)
{
printf("unable to open");
exit(0);
}
do
{
ch=fgetc(fp1);
fputc(ch,fp2);
}
while(ch!=EOF);
fclose(fp1);
fclose(fp2);
getch();
}
Q4. What is file? Explain any five functions used in file handling.
Ans- File: A file is a collection of bytes stored on a secondary storage device, which is generally a disk of
some kind. The collection of bytes may be interpreted, for example, as characters, words, lines,
paragraphs and pages from a textual document; fields and records belonging to a database; or pixels from
a graphical image. The meaning attached to a particular file is determined entirely by the data structures
and operations used by a program to process the file.
FILE is inbuilt structure in c.
1. fopen()
FILE *fopen(const char *path, const char *mode);
The fopen() function is used to open a file and associates an I/O stream with it. This function takes two
arguments. The first argument is a pointer to a string containing name of the file to be opened while the
second argument is the mode in which the file is to be opened.
2.fread()
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
The function fread is used for reading data from the file opened by fopen function. This function accepts
three arguments.
3.fwrite()
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
The function fwrite is used for writing data to the file opened by fopen function. This function accepts
three arguments.
4.fseek()
int fseek(FILE *stream, long offset, int whence);
The fseek() function is used to set the file position indicator for the stream to a new position. This
function accepts three arguments.
5.fclose()
int fclose(FILE *fp);
The fclose() function first flushes the stream opened by fopen() and then closes the underlying descriptor.
Q5.Write a program to read positive integer number from one file DATA.txt and copy even number
in second file EVEN.txt and copy odd number in third file ODD.txt.
Ans-
/*program to read integers numbers from data.txt file and write even number in even.txt and odd number
in odd.txt.*/
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp,*fo,*fe;
int n;
clrscr();
fp=fopen("DATA.TXT","r");
fo=fopen("ODD.TXT","w");
fe=fopen("EVEN.TXT","w");
if(fp==NULL||fo==NULL||fe==NULL)
{
printf("file can not open");
exit(0);
}
while((n=getw(fp))!=EOF)
{
if(n%2==0)
putw(n,fe);
else
putw(n,fo);
}
fclose(fp);
fclose(fo);
fclose(fe);
getch();
}
● #if
● #ifdef
● #ifndef
Optionally, an alternative block of text can be set aside with one of two directives:
● #else
● #elif
The end of the block or alternative block is marked by the #endif directive.
If the condition checked by #if , #ifdef , or #ifndef is true (nonzero), then all lines between the matching
#else (or #elif ) and an #endif directive, if present, are ignored.
If the condition is false (0), then the lines between the #if , #ifdef , or #ifndef and an #else , #elif , or
#endif directive are ignored.
Example1:
Lines of source code that may be sometimes desired in the program and other times not, are surrounded
by #ifdef, #endif directive pairs as follows:
#ifdef DEBUG
printf("debug:x = %d, y = %f\n", x, y);
...
#endif
The #ifdef directive specifies that if DEBUG exists as a defined macro, i.e. is defined by means of a
#define directive, then the statements between the #ifdef directive and the #endif directive are retained in
the source file passed to the compiler. If DEBUG does not exist as a macro, then these statements are not
passed on to the compiler.
Example2:
We can also use #if to test for the presence of a device, for example, so that if it is present, we can include
an appropriate header file.
#if DEVICE == MOUSE
#include mouse.h
#endif
Here, both DEVICE and MOUSE are assumed to be constant identifiers.
Example3:
The #elif provides a multiway branching in conditional compilation analogous to else ... if in C. Suppose,
we wish to write a program that must work with any one of a variety of printers. We need to include in the
program a header file to support the use of a specific printer. Let us assume that the specific printer used
in an installation is defined by a macro DEVICE. We can then write conditional compilation directives to
include the appropriate header file.
#if DEVICE == IBM
#include ibmdrv.h
#elif DEVICE == HP
#include hpdrv.h
#else
#include gendrv.h
#endif
Only constant expressions are allowed in conditional compilation directives. Therefore, in the above code,
DEVICE, IBM, and HP must be defined constants.
Q9. What do you understand by header file in c program? Differentiate two file inclusion methods
#include<filename> and #include” file name “ .
Ans-A header file is a file with extension .h which contains all the constants, macros, system
wide global variables, and function prototypes and to be shared between several source files.
There are two types of header files: the files that the programmer writes and the files that
come with your compiler.
You request the use of a header file in your program by including it, with the C preprocessing directive
#include.
Difference between #include<filename> and #include” file name” :
Both user and system header files are included using the preprocessing directive #include.
It has following two forms:
(1) #include<file>
This form is used for system header files. It searches for a file named file in a standard list of system
directories. You can prepend directories to this list with the -I option while compiling your source code.
(2) #include”file”
This form is used for header files of your own program. It searches for a file named file in the directory
containing the current file. You can prepend directories to this list with the -I option while compiling your source
code.
Q11. Define command line argument.WAP to find sum of n integer numbers given as command line
argument.
Ans: Command line argument is a parameter supplied to the program when it is invoked.
Syntax:
int main(int argc, char *argv[])
Here argc counts the number of arguments on the command line and argv[ ] is a pointer array
which holds pointers of type char which points to the arguments passed to the program.
#include <stdlib.h>
#include <stdio.h>
# include <conio.h>
int main(int argc, char *argv[])
{ int a,b,sum=0;
int i; //for loop counter
for(i=1; i<argc; i++)
{
sum = sum+atoi (argv[i]);
}
printf("SUM =: %d\n",sum);
getch();
}
Ans: A linked list is a list of elements, which are connected together via links.
Linked list can be visualized as a chain of nodes, where every node points to the next node.