PPS IMPORTANT QUESTIONS and Solution
PPS IMPORTANT QUESTIONS and Solution
THEORY:
Input Unit
Input unit consists of devices with the help of which we can enter the information to the
computer. This unit is linked between user and computer. Input devices translate user
input into the form of computer language.
Ex – Keyword, Mouse, OMR, OCR, BCR, etc.
Operating System
An operating system is a program that acts as an interface between the software
and the computer hardware.
It is a specialised software that controls and monitors the execution of all other
programs that reside in the computer, including application programs and other
system software.
To act as an intermediary between the hardware and its users and making it easier
for the users to access and use other resources.
Keep track of who is using which resource, granting resource requests, according
for resource using and mediating conflicting requests from different programs and
users.
The efficient and fair sharing of resources among users and
programs.
Device Management - - Keeps tracks of all devices. This is also called I/O controller.
Decides which process gets the device when and for how much time.
File Management - - Allocates the resources. Deallocates the resource. Decides who
gets the resources.
Job accounting - - Keeping track of time & resources used by various jobs and/or
users.
Interaction with the operators - - The interaction may take place via the console of
the computer in the form of instructions. Operating System acknowledges the
same, do the corresponding action and inform the operation by a display screen.
Error- detecting aids - - Production of dumps, traces, error messages and other
debugging and error- detecting methods.
Application Software
System Software
The system software is a collection of programs designed to operate, control and
extend the processing capabilities of the computer itself. System software are
generally prepared by computer manufacturers.
Close to system.
Fast in speed.
Difficult to design.
Difficult to understand.
Less interactive.
Smaller in size.
Difficult to manipulate.
Application Software
Application softwares are the softwares that are designed to satisfy a particular
need of a particular environment. All softwares prepared by us in the computer lab
can come under the category of Application Software.
Payroll Software
Microsoft Word
Microsoft Excel
Microsoft Powerpoint
Computer – Types
Computers can be broadly classified by their speed and computing power.
Sr.
Type Specifications
No.
PC (Personal Computer)
A PC can be defined as a small, relatively inexpensive computer designed for an individual
user. PCs are based on the microprocessor technology that enables manufacturers to put
an entire CPU on one chip. Businesses use personal computers for word processing,
accounting, desktop publishing, and for running spreadsheet and database management
applications. At home, the most popular use for personal computers is for playing games
and surfing the Internet.
Although personal computers are designed as single- user systems, these systems are
normally linked together to form a network. In terms of power, nowadays high- end models
of the Macintosh and PC offer the same computing power and graphics capability as low-
end workstations by Sun Microsystems, Hewlett- Packard, and DELL.
WorkStation
Workstation is a computer used for engineering applications (CAD/CAM), desktop
publishing, software development, and other such types of applications, which require a
moderate amount of computing power and relatively high quality graphics capabilities.
Workstations generally come with a large, high- resolution graphics screen, large amount
of RAM, inbuilt network support, and a graphical user interface. Most workstations also
have a mass storage device such as a disk drive, but a special type of workstation, called a
diskless workstation, comes without a disk drive.
Common operating systems for workstations are UNIX and W indows NT. Like PC,
Workstations are also single- user computers. However, workstations are typically linked
together to form a local- area network, although they can also be used as stand- alone
systems.
Minicomputer
It is a midsize computer. A minicomputer is a multi- processing system capable of
supporting from up to 250 users simultaneously
Mainframe
Mainframe is a very large in size and an expensive computer capable of supporting
hundreds, or even thousands, of users simultaneously. Mainframe executes many
programs concurrently. Mainframes support many simultaneous programs execution
Supercomputer
Supercomputers are one of the fastest computers currently available. Supercomputers are
very expensive and are employed for specialized applications that require immense
amounts of mathematical calculations (number crunching). For example, weather
forecasting, scientific simulations, (animated) graphics, fluid dynamic calculations, nuclear
energy research, electronic design, and analysis of geological data (e.g. in petrochemical
prospecting).
Output: An algorithm produces at least one output. Every instruction that contains
a fundamental operator must accept zero or more inputs.
Finiteness: An algorithm must terminate after a finite number of steps in all test
cases. Every instruction which contains a fundamental operator must be terminated
within a finite amount of time. Infinite loops or recursive functions without base
conditions do not possess finiteness.
In Memory Hierarchy the cost of memory, capacity is inversely proportional to speed. Here
the devices are arranged in a manner Fast to slow, that is form register to Tertiary
memory.
Let us discuss each level in detail:
Level- 0 − Registers
The registers are present inside the CPU. As they are present inside the CPU, they have
least access time. Registers are most expensive and smallest in size generally in kilobytes.
They are implemented by using Flip- Flops.
Level- 1− Cache
Cache Memory is used to store the segments of a program that are frequently accessed
by the processor. It is expensive and smaller in size generally in Megabytes and is
implemented by using Static RAM.
Level- 2 − Primary or Main Memory
It directly communicates with the CPU and with auxiliary memory devices through an I/O
processor. Main memory is less expensive than cache memory and larger in size generally
in Gigabytes. This memory is implemented by using Dynamic RAM.
Level- 3 − Secondary storage
Secondary Storage Devices like Magnetic Disk are present at level 3. They are used as
backup storage. They are cheaper than main memory and larger in size generally in a few
TB.
Level- 4 − Tertiary storage
Tertiary storage devices like magnetic tape are present at level 4. They are used to store
removable files and are the cheapest and largest in size (1- 20 TB).
Relational O perators
The following table shows all the relational operators supported by C. Assume
variable A holds 10 and variable B holds 20 then –
Examples :-
Exampl
Operator Description
e
(A ==
Checks if the values of tw o operands are
B) is
== equal or not. If yes, then the condition
not
becomes true.
true.
Checks if the values of tw o operands are
(A != B)
!= equal or not. If the values are not equal,
is true.
then the condition becomes true.
Checks if the value of left operand is (A > B)
> greater than the value of right operand. is not
If yes, then the condition becomes true. true.
Checks if the value of left operand is less
(A < B)
< than the value of right operand. If yes,
is true.
then the condition becomes true.
Checks if the value of left operand is (A >=
greater than or equal to the value of right B) is
>=
operand. If yes, then the condition not
becomes true. true.
Checks if the value of left operand is less
(A <=
than or equal to the value of right
<= B) is
operand. If yes, then the condition
true.
becomes true.
Logical O perators
Following table shows all the logical operators supported by C language. Assume
variable A holds 1and variable B holds 0, then −
Show Examples
Exampl
Operator Description
e
Called Logical AND operator. If both the (A &&
&& operands are non-zero, then the B) is
condition becomes true. false.
Called Logical OR Operator. If any of the
(A || B)
|| tw o operands is non-zero, then the
is true.
condition becomes true.
Called Logical NOT Operator. It is used to
!(A &&
reverse the logical state of its operand. If
! B) is
a condition is true, then Logical NOT
true.
operator w ill make it false.
Bitwise O perators
Bitwise operator works on bits and perform bit- by- bit operation. The truth tables for &, |,
and ^ is as follows −
p q p & q p | q p ^ q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
Assume A = 60 and B = 13 in binary format, they will be as follows −
A = 00111100
B = 0000 1101
- - - - - - - - - - - - - - - - -
A&B = 0000 1100
A|B = 00111101
A^ B = 00110001
~A = 1100 0011
The following table lists the bitwise operators supported by C. Assume variable 'A' holds
60 and variable 'B' holds 13, then −
Examples :-
Exampl
Operator Description
e
(A & B)
= 12,
Binary AND Operator copies a bit to the
& i.e.,
result if it exists in both operands.
0000
1100
(A | B)
Binary OR Operator copies a bit if it = 61,
|
exists in either operand. i.e.,
00111101
(A ^ B)
= 4 9,
Binary XOR Operator copies the bit if it is
^ i.e.,
set in one operand but not both.
0011
0001
(~A ) =
Binary One's Complement Operator is ~(60),
~
unary and has the effect of 'flipping' bits. i.e,.
- 0111101
Binary Left Shift Operator. The left A << 2
operands value is moved left by the = 24 0
<<
number of bits specified by the right i.e., 1111
operand. 0000
>> Binary Right Shift Operator. The left A >> 2
= 15
operands value is moved right by the i.e.,
number of bits specified by the right 0000
operand. 1111
Assignment O perators
The following table lists the assignment operators supported by the C language −
Examples :-
Operator Description Example
C=A+
B w ill
Simple assignment operator. Assigns assign
= values from right side operands to left the
side operand value of
A + B to
C
C += A
Add AND assignment operator. It adds is
+= the right operand to the left operand equivale
and assign the result to the left operand. nt to C =
C + A
Subtract AND assignment operator. It C -= A is
subtracts the right operand from the equivale
-=
left operand and assigns the result to nt to C =
the left operand. C - A
Multiply AND assignment operator. It C *= A is
multiplies the right operand w ith the equivale
*=
left operand and assigns the result to nt to C =
the left operand. C * A
Divide AND assignment operator. It C /= A is
divides the left operand w ith the right equivale
/=
operand and assigns the result to the nt to C =
left operand. C / A
C %= A
Modulus AND assignment operator. It is
%= takes modulus using tw o operands and equivale
assigns the result to the left operand. nt to C =
C % A
C <<= 2
is same
<<= Left shift AND assignment operator.
as C = C
<< 2
C >>= 2
is same
>>= Right shift AND assignment operator.
as C = C
>> 2
&= Bitw ise AND assignment operator. C &= 2
is same
as C = C
& 2
C ^ = 2 is
Bitw ise exclusive OR and assignment
^ = same as
operator.
C = C ^ 2
C |= 2 is
Bitw ise inclusive OR and assignment
|= same as
operator.
C = C | 2
a) Keyword
Ans:
A keyw ord is a reserved w ord. You cannot use it as a variable name, constant name, etc. There are
only 32 reserved w ords (keyw ords) in the C language.
A list of 32 keyw ords in the c language is given below :
auto break case char const continue default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct sw itch typedef union unsigned void volatile w hile
We w ill learn about all the C language keyw ords later.
b) Comment
c) Data type
d) Statement
9. W hat is storage class? Define all storage class w ith example.
Ans:
C Storage Classes are used to describe the features of a variable/function. These features
basically include the scope, visibility, and lifetime w hich help us to trace the existence of a
particular variable during the runtime of a program.
if statement in C
In the C programming language, w e use the if statement for conditional branching. It allow s a
program to evaluate if a given condition is true or false and execute a block of code accordingly.
Syntax:
if (condition)
{
// statements to execute if condition is true
}
Sw itch statement in C
The sw itch statement is a control flow statement in C (and many other programming languages)
that allow s you to choose one of several possible code blocks to execute based on the value of an
expression. It’s often used as a more concise alternative to a series of if- else statements w hen
you need to compare a single value against multiple possible values.
Syntax :
sw itch (expression) {
case value1:
// code w ill be executed if expression equals value1
break;
case value2:
// code w ill be executed if expression equals value2
break;
// additional cases...
default:
// code w ill be executed if none of the above cases match
}
11. W hat is function and recursive function? Define w ith syntax.
Ans:
12. W hat is file handling? Write some function using file handling.
Ans:
File handing in C is the process in w hich w e create, open, read, w rite, and close operations
on a file. C language provides different functions such as fopen(), fw rite(), fread(), fseek(),
fprintf(), etc. to perform input, output, and many different C file operations in our program.
Types of Files in C
A file can be classified into tw o types based on the w ay the file stores the data. They are as
follow s:
Text Files
Binary Files
Text Files
A text file contains data in the form of ASCII characters and is generally used to store a stream of
characters.
Each line in a text file ends w ith a new line character (‘ \n’).
It can be read or w ritten by any text editor.
They are generally stored w ith .txt file extension.
Text files can also be used to store the source code.
2. Binary Files
A binary file contains data in binary form (i.e. 0’s and 1’s) instead of ASCII characters. They contain
data that is stored in a similar manner to how it is stored in the main memory.
The binary files can be created only from w ithin a program and their contents can only be
read by a program.
More secure as they are not easily readable.
They are generally stored w ith .bin file extension.
C File O perations
C file operations refer to the different possible operations that w e can perform on a file in C such
as:
1. Creating a new file – fopen() w ith attributes as “a” or “a+” or “ w ” or “ w +”
2. Opening an existing file – fopen()
3. Reading from file – fscanf() or fgets()
4. Writing to a file – fprintf() or fputs()
5. Moving to a specific location in a file – fseek(), rew ind()
6. Closing a file – fclose()
File Pointer in C
A file pointer is a reference to a particular position in the opened file. It is used in file handling to
perform all file operations such as read, w rite, close, etc. We use the FILE macro to declare the file
pointer variable. The FILE macro is defined inside <stdio.h> header file.
Syntax of File Pointer
FILE* pointer_name;
File Pointer is used in almost all the file operations in C.
O pen a File in C
For opening a file in C, the fopen() function is used w ith the filename or file path along w ith the
required access modes.
Syntax of fopen()
File Pointer in C
A file pointer is a reference to a particular position in the opened file. It is used in file handling to
perform all file operations such as read, w rite, close, etc. We use the FILE macro to declare the file
pointer variable. The FILE macro is defined inside <stdio.h> header file.
Syntax of File Pointer
FILE* pointer_name;
File Pointer is used in almost all the file operations in C.
O pen a File in C
For opening a file in C, the fopen() function is used w ith the filename or file path along w ith the
required access modes.
Syntax of fopen()
Opening
Modes Description
Searches file. If the file is opened successfully fopen( ) loads it into memory and sets
r up a pointer that points to the first character in it. If the file cannot be opened
fopen( ) returns NULL.
rb Open for reading in binary mode. If the file does not exist, fopen( ) returns NULL.
Open for w riting in text mode. If the file exists, its contents are overw ritten. If the
w
file doesn’t exist, a new file is created. Returns NULL, if unable to open the file.
Open for w riting in binary mode. If the file exists, its contents are overw ritten. If the
w b
file does not exist, it w ill be created.
Searches file. If the file is opened successfully fopen( ) loads it into memory and sets
a up a pointer that points to the last character in it. It opens only in the append mode.
If the file doesn’t exist, a new file is created. Returns NULL, if unable to open the file.
Open for append in binary mode. Data is added to the end of the file. If the file
ab
does not exist, it w ill be created.
Searches file. It is opened successfully fopen( ) loads it into memory and sets up a
r+
pointer that points to the first character in it. Returns NULL, if unable to open the file.
Open for both reading and w riting in binary mode. If the file does not exist, fopen( )
rb+
returns NULL.
Searches file. If the file exists, its contents are overw ritten. If the file doesn’t exist a
w +
new file is created. Returns NULL, if unable to open the file.
Open for both reading and w riting in binary mode. If the file exists, its contents are
w b+
overw ritten. If the file does not exist, it w ill be created.
Searches file. If the file is opened successfully fopen( ) loads it into memory and sets
a+
up a pointer that points to the last character in it. It opens the file in both reading
and append mode. If the file doesn’t exist, a new file is created. Returns NULL, if
unable to open the file.
Open for both reading and appending in binary mode. If the file does not exist, it
ab+
w ill be created.
13. W hat are macros? Define conditional and null conditional macros.
Ans:
Working of C Preprocessor
The C preprocessor is a macro preprocessor (allow s you to define macros) that transforms your
program before it is compiled. These transformations can be the inclusion of header files, macro
expansions, etc.
All preprocessing directives begin w ith a # symbol. For example,
#define PI 3.14
Some of the common uses of C preprocessors are:
#include "my_header.h"
Visit this page to learn more about using header files.
#include <stdio.h>
#define PI 3.14 15
int main()
{
float radius, area;
printf("Enter the radius: ");
scanf("%f", &radius);
printf("Area=% .2f",area);
return 0;
}
#include <stdio.h>
#define PI 3.14 15
#define circleArea(r) (PI*r*r)
int main() {
float radius, area;
return 0;
}
Visit this page to learn more about macros and #define preprocessor.
Conditional Compilation
In C programming, you can instruct the preprocessor w hether to include a block of code or not. To
do so, conditional directives can be used.
Uses of Conditional
to exclude certain code from the program but to keep it as a reference for future purposes
To use conditional, #ifdef, #if, #defined, #else and #elif directives are used.
#ifdef Directive
#ifdef MACRO
// conditional codes
#endif
Here, the conditional codes are included in the program only if MACRO is defined.
#if, #elif and #else Directive
#if expression
// conditional codes
#endif
Here, expression is an expression of integer type (can be integers, characters, arithmetic
expression, macros, and so on).
The conditional codes are included in the program only if the expression is evaluated to a non-zero
value.
The optional #else directive can be used w ith #if directive.
#if expression
conditional codes if expression is non-zero
#else
conditional if expression is 0
#endif
You can also add nested conditional to your #if...#else using #elif
#if expression
// conditional codes if expression is non-zero
#elif expression1
// conditional codes if expression is non-zero
#elif expression2
// conditional codes if expression is non-zero
#else
// conditional if all expressions are 0
#endif
#defined
The special operator #defined is used to test w hether a certain macro is defined or not. It's often
used w ith #if directive.
#if defined BUFFER_SIZE && BUFFER_SIZE >= 204 8
// codes
Predefined Macros
Here are some predefined macros in C programming.
Macro Value
__DATE__ A string containing the current date.
a) Calloc()
b) Malloc()
c) Alloc()
d) Free()
Ans:
* Dereference Operator
& Addressof Operator
= Assignment
CPU utilization is more in the case of a Compiler. CPU utilization is less in the case of a Interpreter.
The use of Compilers mostly happens in The use of Interpreters is mostly in Programming an
Production Environment. Environments.
Object code is permanently saved for future use. No object code is saved for future use.
C, C++, C#, etc are programming languages that Py thon, Ruby, Perl, SNOBOL, MATLAB, etc are progra
are compiler-based. interpreter-based.
Ans:
Difference Between while and do - while
while do-while
Entry Control Loop Exit Control Loop
First checking the condition, if true then Without checking the condition, In first time it
do the block w ork. must do the block w ork.
Not terminated by “ ; ” Must terminated by “ ; ”
Not use “ do ” Use “ do ”
Syntax: Syntax:
w hile (condition) { do{
statement 1; statement 1;
statement 2; statement 2;
...... ......
. . . . . . . . . . . .
Statement n; Statement n;
Increment or decrement or update Increment or decrement or update
} }w hile(condition);
c) RAM & RO M
Ans:
d) if & switch
Ans:
Difference Between If and Switch
If Switch
It can check only one case, not multiple
We can check multiple cases in one time
case
We can pass condition also We pass only expression, not condition
Use “else” Use “default”
It do not use “case” It use “case”
Syntax: Syntax:
if (condition) sw itch (expression) {
{ case value1:
// statements to execute statement 1;
if condition is true break;
} case value2:
else statement 2;
{ break;
// statements to execute . . . . . . . . .
if condition is false . . . . . . . . .
} case n;
statement n;
break;
default:
// code w ill be executed
if none of the above cases match
}
Ans. Loop –It means rotating any block till the condition is true.
There are three types of loops:-
(i) W hile loop : - It is a loop which is used for rotating any block. In this loop
first check the condition, If the condition is true then go to the block
and do all the statement. In the last statement do the increment or
decrement or update. After that again checking the condition. If true
then again do all the above work otherwise comeback from the loop.
Syntax:
w hile (condition) {
statement 1;
statement 2;
......
. . . . . .
Statement n;
Increment or decrement or update
}
#include <conio.h>
void main(){
int n, f= 1;
clrscr();
f *= n;
n- -;
}
printf("Factorial is : % d", f);
getch();
}
(ii) For loop : - It is a loop which is used for rotating any block. In this loo, it
has three parts:-
(a) Initialization
(b) Condition
All these parts are separated by “ ; ”. In this loop first initialize the variable
after that checking the condition. If the condition is true then go to the
block and do all the statement after that do increment or decrement
and checking the condition, if the condition is true, then again do the
block work otherwise comeback from the loop
Syntax:
for (initialization; condition; increment or decrement) {
statement 1;
statement 2;
......
. . . . . .
Statement n;
}
Example: To find the factorial of any number.
#include <stdio.h>
#include <conio.h>
void main(){
int n, f= 1;
clrscr();
for(int i = 1;i<=n;i++){
f*=i;
}
getch();
}
(iii) do - W hile loop : - It is a loop which is used for rotating any block. In this
loop first do the statement of the block. In the second time, it
checking the condition, if true then again do the block work,
otherwise comeback from the loop.
Syntax:
do{
statement 1;
statement 2;
......
. . . . . .
Statement n;
Increment or decrement or update
} w hile (condition);
#include <conio.h>
void main(){
int n, f= 1;
clrscr();
do{
f *= n;
n- -;
}w hile(n>0);
getch();
}
19. W hat is link list? Define all type of link list.
a) Armstrong
b) Prime number
c) Greater number
PRO GRAMS:
Ans:
#include <stdio.h>
#include <conio.h>
void main(){
int a,b,c,d,e;
clrscr();
a = (a>b) ? a : b;
a = (a>c) ? a : c;
a = (a>d) ? a : d;
a = (a>e) ? a : e;
getch();
return 0;
}
Ans:
#include <stdio.h>
#include <conio.h>
void main(){
int x, y, z;
if(x>y){
if(x>z){
}
else{
}
}
else{
if(y>z){
}
else{
}
}
getch();
return 0;
}
Ans:
# include <stdio.h>
#include <conio.h>
void main(){
char ch;
clrscr();
sw itch (ch){
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
printf("Vow el");
break;
default:
}
getch();
return 0;
}
4. W rite a program to find the area of square, circle, rectangle and triangle.
Ans :
#include <stdio.h>
#include <conio.h>
void main(){
int ch;
float a,b;
clrscr();
sw itch (ch){
case 1:
a = a * b;
break;
case 2:
a = (22 / 7) * a * a;
break;
case 3:
a = (a * b) / 2;
break;
default:
}
getch();
}
Ans:
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main(){
int n, m, t, k, c = 0, s = 0;
clrscr();
t = m = n;
c++;
t = t / 10;
}
k = m%10;
s = s + pow(k,c);
k = k / 10;
}
getch();
}
void main(){
int n, k, s = 0;
clrscr();
k = n % 10;
s = s * 10 + k;
n = n / 10;
}
getch();
}
Ans:
#include <stdio.h>
#include <conio.h>
void main(){
clrscr();
for(i = 1;i<=n;i++){
c = 0;
for(j = 1;j<=i;j++){
if(i % j == 0){
c++;
}
if(c == 2){
k++;
}
}
getch();
}
a)
b)
c) ……
(i)
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
int n, i, f = 1, p;
float s = 0;
clrscr();
{
p = pow(i, i);
f *= i;
s = s + (float)p / f;
}
getch();
}
(iii)
#include <stdio.h>
#include <conio.h>
void main(){
int n, k = 0, s = 0;
clrscr();
k = k * 10 + 1;
s += k;
n- -;
}
getch();
}
a) 1
2 3
4 5 6
7 8 9 10
1112 13 14 15
#include <stdio.h>
#include <conio.h>
void main(){
int n = 5, i, j, k = 1;
clrscr();
}
printf("\n");
}
getch();
}
Ans:
b) 5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
Ans:
#include <stdio.h>
#include <conio.h>
void main(){
int n = 5, i, j;
clrscr();
}
printf("\n");
}
getch();
}
c) 1
10
10 1
10 10
10 10 1
Ans:
#include <stdio.h>
#include <conio.h>
void main(){
int n = 5, i, j;
clrscr();
if (j % 2 == 0)
else
}
printf("\n");
}
getch();
}
d) 5 5 5 5 5
4 4 4 4
3 3 3
2 2
1
Ans:
#include <stdio.h>
#include <conio.h>
void main(){
int n = 5, i, j;
clrscr();
}
printf("\n");
}
getch();
}
e) +
+ -
+ - +
+ - + -
+ - + - +
Ans:
#include <stdio.h>
#include <conio.h>
void main(){
int n = 5, i, j;
clrscr();
if (j % 2 == 0)
printf("- ");
else
printf("+ ");
}
printf("\n");
}
getch();
}
f) I
I I
I I M
I I M T
Ans:
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main(){
int i, j;
char n[] = "IIMT";
clrscr();
printf("%c", n[j]);
}
printf("\n");
}
getch();
}
i. Selection
ii. Bubble
iii. Insertion
void main()
{
int i, j, temp;
clrscr();
{
{
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
{
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, temp;
clrscr();
for (i = 0; i < n; i++)
{
temp = arr[j];
arr[j + 1] = temp;
}
}
}
{
}
getch();
}
void main() {
clrscr();
for(i = 0;i<len;i++){
key = arr[i];
j = i-1;
arr[j+1] = arr[j];
j- -;
}
arr[j+1] = key;
}
for(i = 0;i<len;i++){
}
getch();
}
rd
12. W rite a program to enter two 3x3 matrix and multiply in 3 matrix.
13. W rite a program to enter any 3x3 matrix and transpose it.
14. W rite a program to search any value from the list. linear search ,binary
search
Ans:
Linear Search
#include <stdio.h>
#include <conio.h>
void main()
{
int n, i, x = 0;
clrscr();
scanf("%d", &n);
{
if (arr[i] == n)
{
x = 1;
break;
}
}
if (x == 1)
printf("Present");
else
printf("Not Present");
getch();
}
Binary Search
#include <stdio.h>
#include <conio.h>
void main()
{
int arr[] = {10, 11, 16, 17, 2, 7, 1, 8, 5, 15, 12, 18, 4 , 20, 19, 3};
int i, j, v, l, h, x = 0;
v = arr[i];
arr[i] = arr[j];
arr[j] = v;
}
}
}
l = 0;
h = len - 1;
v = (l + h) / 2;
if (arr[v] == n){
x = 1;
break;
}
h = v - 1;
}
else{
l = v + 1;
}
}
if (x == 1)
printf("Present");
else
printf("Not Present");
getch();
}
Ans:
#include <stdio.h>
#include <conio.h>
void main()
{
int n, i = 0, k, arr[10];
clrscr();
scanf("%d", &n);
{
k = n % 2;
arr[i] = k;
i++;
}
i- -;
{
printf("%d", arr[k]);
}
getch();
}
18. W rite a program to write all squares between 1to 10 inside the file and
read it.