Ilovepdf Merged

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

EST102 Programming in C

https://www.keralanotes.com/
contain only data of the same type.The keyword ‘struct’ is used to create a structure. A
structure variable can either be declared with structure declaration or as a separate
declaration like basic types.

Consider we want to create the structure of a person with following variables


name, age and address. Then such a structure can be created as

https://www.keralanotes.com/
EST102 Programming in C struct Person
{
char name[30];
Read Only Memory (ROM): ROM is a non-volatile memory and hence retains its contents int age;
EST102 Programming in C
even when the computer is switched off. It is used for storing software that is rarely char addr[50];

https://www.keralanotes.com/
changed during the life of the system, sometimes known as firmware. Almost every
};

https://www.keralanotes.com/
y: 20 b: 20 computer comes with a small amount of ROM containing the boot firmware which is The general format of a structure definition is as follows
EST102 Programming in C

m
essential for the boot-up. BIOS is a firmware used to perform hardware initialization struct structure_name{
data_type member1;
After the swap call, formal parameters get swapped but actual parameters remains the the booting process and to provide runtime services for operating systems and
during
same. DVD: It stands for The
programs. Digital
BIOS Versatile Diskpre-installed
firmware comes or Digital onVideo Disk.
the ROM andItitlooks justsoftware
is the first like a CD and use
data_type member2;
---------------------
---------------------
co
s.
x: a: to run when the computer is powered on. ROM memories have gradually evolved from };
10 20 a similar technology as that of the CDs but allows tracks to be spaced closely enough to
te

fixed read-only memories to memories that can be programmed and then re-programmed.
In defining a structure you may note the following syntax:
y: 20 b: 10 store data that is more than six times the CD’s capacity. It is a significant advancement in
no

 ROM (Read Only Memory)  The template is terminated with a semicolon.


m

portable storage technology. A DVD holds 4.7 GB to 17 GB of data.


 PROM (Programmable Read Only Memory) EST102 Programming in C  While the entire definition is considered as a statement, each member is declared
la
co

https://www.keralanotes.com/ independently for its name and type in a separate statement inside the template.
Blue Ray Disk:
 EPROM (Erasable Programmable Read Only Memory).
This is the latest optical storage media to store high definition audio and
ra

TYPES OF USER DEFINED FUNCTIONS STRUCTURE OF A C PROGRAM


s.

 EEPROM (Electrically Erasable Programmable Read Only Memory) Difference between Structure and Array
video. It is similar to a CD or DVD but can store up to 27 GB of data on a single layer disk
ke
m


te

Functions with no arguments and no return values


Array Structure
 Complementary Metal Oxide Semiconductor (CMOS): CMOS is a technology used to
and up to 54 GB of data on a dual layer disk. While CDs or DVDs use red laser beam, the
co

 Functions with arguments and no return values An array is a collection of related data Structure can have elements of different
no

produce integrated circuits, but the term is commonly used to refer to the CMOS elements of same type. types.
 Functions with no arguments and but return a value An array is derived data type Structure is a programmer defined one
blue ray diskmemory
uses a on
blue
the laser
motherto read/write
board. It is knowndata on a diskRAM (NVRAM). It is powered
as non-volatile
s.

Any array behaves like built in data type. In Structure we have to design and
 Functions with arguments and one return values
la

by an onboard battery and stores system setting configurations that are required at All we have to do is to declare an array declare a data structure before the
te

 Function that have multiple return values(work based on condition) variable and use it variable of that type are declared and
Solid State Memories:
boot time . In Solid-state storage
case the battery runs out,devices
the CMOSare based
is reset on electronic
and loses circuits with no
all custom settings
ra

used.
including the system clock. The information needs to be restored after replacing the EST102 Programming in C
no

moving partsbattery.
like the reels of tape, spinning discs etc. Solid-state storage devices use
m
ke

https://www.keralanotes.com/Declaring Structure Variable


special memories
Secondarycalled flash memory to store data. Solid
storagestate driveand(or flash memory) is After defining a structure format we can declare variables of that type. A
la

 Functions with no arguments and no return values Memory: - Primary memory has limited capacity is volatile. STRUCTURE OF A C PROGRAM
.co

structure variable declaration is similar to the declaration of variables of any other data
1. Documentation section: The documentation section consists of a set of comment
used mainly in digital
Secondary cameras,
memory penthis
overcomes drives or USB
limitation flash drives.
by providing permanent storage of data and
ra

// function to read two numbers and print its sum type. It includes the following elements.
o

in bulk quantity. They are the slowest and cheapest form of memory. It cannot be accessed lines giving the name of the program, the author and other details, which the
void add()
.c
ke

programmer would like to use later.


{ Pen Drives:
directly by the CPU. Programs need to be moved to primary memory in order to be
Pen Drives or Flash drives are the recently emerged portable storage media. It IIPE 17
es

2. Link section: The link section provides instructions to the compiler to link
es

int a,b,sum; executed by the CPU. Secondary memory is also termed as external memory and refers to
For More Study Materials : www.keralanotes.com
printf("Enter the values of a & b"); is an EEPROM based
the various flash
storage memory
media on which awhich can
computer can be
storerepeatedly erased and written using
data and programs. functions from the system library such as using the #include directive.
ot

scanf("%d%d",&a,&b); 3. Definition section: The definition section defines all symbolic constants such using
electric signals.The
This memory is accompanied with a USB connector which
mediaenables the pen
ot

https://www.keralanotes.com/
sum = a+b; secondary storage media can be fixed or removable. Fixed storage is an
EST102 Programming in C the #define directive.
an

printf("Sum=%d",sum); internal storage medium like hard disk that is fixed inside the computer. Fixed storage
} drive to connect to the computer. They have a capacity smaller than a hard disk but greater
4. Global declaration section: There are some variables that are used in more than
devices are literally not fixed; obviously these can be removed from the system for
lan

one function. Such variables are called global variables and are declared in the
l

IIPE 4
ra

 Functions with arguments and no return values than a CD. repairing work, maintenance purpose, and also for upgrade etc. Technically, almost all of global declaration section that is outside of all the functions. This section also
om

For More Study Materials : www.keralanotes.com


the data i.e. being processed on a computer system is stored on some type of a built-in 1. Documentation section: The documentation section consists of a set of comment
ke

// function that takes two arguments and print their sum. declares all the user-defined functions.
void add(int a,int b) fixed storage device. Storage medium that are portable and can be taken outside the lines giving the name of the program, the author and other details, which the
5. main () function section: Every C program must have one main function section.
.c
ra

{ EST102 computer are termed as removable storage media. programmer would like to use later.
int sum; EST102 Programming
Programming in
in CC This section contains two parts; declaration part and executable part
2. Link section: The link section provides instructions to the compiler to link
es

sum= a + b; https://www.keralanotes.com/
https://www.keralanotes.com/ Following are the main types of storage media:
 Declaration part: The declaration part declares all the variables used in the
functions from the system library such as using the #include directive.
ke

printf("Sum=%d",sum);
printf("Sum=%d",sum); executable part.
ot

}} Magnetic Storage Media: Magnetic media is coated with a magnetic layer which is 3. Definition section: The definition section defines all symbolic constants such using
IIPE 6  Executable part: There is at least one statement in the executable part. These
the #define directive.
an

magnetized in clockwise or anticlockwise directions. When the disk moves, the head two parts must appear between the opening and closing braces. The program
 Functions
Functions with
For no
no arguments
More
with and
and return
Study Materials
arguments one
one value
: www.keralanotes.com
return value interprets the data stored at a specific location in binary 1s and 0s at reading. Examples: 4. Global declaration section: There are some variables that are used in more than
execution begins at the opening brace and ends at the closing brace. The closing
//
// function
function to
to read
read two
two numbers
numbers and
and return
return its
its sum one function. Such variables are called global variables and are declared in the
l

sum hard disks, floppy disks and magnetic tapes.


m

brace of the main function is the logical end of the program. All statements in the
ra

int global declaration section that is outside of all the functions. This section also
int add()
add() declaration and executable part end with a semicolon. EST102 Programming in C
Floppy Disk: A floppy disk is a flexible disk with a magnetic coating on it. It is packaged
co

{{
ke

declares all the user-defined functions.


6. Subprogram section: If the program is a multi-function program then the
int
int a,b,sum;
a,b,sum; inside a protective plastic envelope. These are one of the oldest types of portable storage https://www.keralanotes.com/
5. main () function section: Every C program must have one main function section.
subprogram section contains all the user-defined functions that are called in the
printf("Enter
printf("Enter the
the values
values of
of aa &
& b");
s.

b"); devices that could store up to 1.44 MB of data but now they are not used due to very less This section contains two parts; declaration part and executable part
scanf("%d%d",&a,&b);
scanf("%d%d",&a,&b); main () function. User-defined functions are generally placed immediately after the
memory storage. IIPE
 Declaration part: The declaration part declares all the variables used in the 7
sum
sum = = a+b;
te

a+b; main ()For


function
More although
Studythey may appear
Materials in any order.
: www.keralanotes.com
return
return sum;
sum; executable part.
Hard disk: A hard disk consists of one or more circular disks called platters which are  Each function consists of
no

}}  Executable part: There is at least one statement in the executable part. These
mounted on a common spindle. Each surface of a platter is coated with a magnetic o A header
two parts must appear between the opening and closing braces. The program
 Functions
Functions with
with arguments
arguments and
and one
one return
return value o A compound statement
mm

value material. Both surfaces of each disk are capable of storing data except the top and bottom
la

execution begins at the opening brace and ends at the closing brace. The closing
disk where only the inner surface is used. The information is recorded on the surface of the  Header
//
// function
function that
that takes
takes two
two arguments
arguments and
and print
print their
their sum.
ccoo

ra

sum. brace of the main function is the logical end of the program. All statements in the
rotating disk by magnetic read/write heads. These heads are joined to a common arm o Specifies the name of the function
int
int add(int
add(int a,int
a,int b)
b) declaration and executable part end with a semicolon.
{{ known as access arm. o Type of returning value
ke
ss..

6. Subprogram section: If the program is a multi-function program then the


return o An optional list of arguments within parenthesis
return (a(a +
+ b);
b);
Optical Storage Media: In optical storage media information is stored and read using a
}} IIPE 6
ttee

/* program to calculate the area of a circle */ /* title (comment) */


laser beam. The data is stored as a spiral pattern of pits and ridges denoting binary 0 and
om

Function IIPE 7
Function that
that have
have multiple
multiple return
return values #include <stdio.h> / * library file acces */
values
For More Study Materials : Downloaded
www.keralanotes.comfrom void
noo

#include
binary 1. Examples: CDs and DVDs For More Study Materials : www.keralanotes.com
Ktunotes.in
#include <stdio.h>
<stdio.h> main( ) / * function heading */
int even(num) Compact Disk: A Compact Disc drive (CDD) is a device that a computer uses to read data {
https://www.keralanotes.com/
EST102 Programming in C

Examples: Microsoft Disk Operating System (MS-DOS), Windows 7, Windows XP, Linux, UNIX,
and Mac OS X Snow Leopard.
APPLICATION SOFTWARE

The software that a user uses for accomplishing a specific task is the application
software. Application software may be a single program or a set of programs. It runs on the
platform which is provided by system software. High level languages are used to write the
application software. It is a specific purpose software.
Examples
 Word Processing Software: For writing letter, reports, documents etc. (e.g. MS-
WORD).

om
 Image Processing Software: For assisting in drawing and manipulating graphics (e.g.
Adobe Photoshop).
https://www.keralanotes.com/
EST102 Programming in C

.c
The main difference between System Software and Application Software is that
counter (PC) always stores the address of the next instruction to be executed by the without system software, system cannot run on the other hand without application
processor. software, system always runs.
es
ot
 The Cache Memory: - It is a small piece of high speed volatile memory located closer
SL. NO SYSTEM SOFTWARE APPLICATION SOFTWARE
an

to the processor for fast processing. Cache memory is made of high speed SRAMs. It

https://www.keralanotes.com/
EST102 Programming in C acts as a buffer between the CPU and the RAM. It holds frequently accessed data and System Software maintains the
system resources and give the Application software is built for
al

instructions so that they can be easily supplied to the CPU when requested again. Cache 1
It also controls all devices such as memory, input/output devices connected to the CPU. path for application software to specific tasks.
memory is used to reduce the average time to access data from the Main memory.
r

run
 Additionally, CPU also has a set of registers for temporary storage of data, instructions,
ke

 Primary Memory: - The memory chips that the processor can directly access are Low level languages are used to High level languages are used to
addresses and intermediate results of calculation 2
write the system software. write the application software.
 When the ALU, CU and the registers are all integrated on a single chip, it is called a referred to as primary memory. The three types of primary memory are RAM, ROM and EST102 Programming in C
3 Machine Dependent Machine independent
CMOS. RAM is volatile whereas ROM as CMOS are non-volatile memories. They are
https://www.keralanotes.com/
om

microprocessor thereby capturing the entire CPU on a single chip


metal oxide semiconductor memory cells built on silicon based ICs.
4 TheItstandard
is a general-purpose software.
library functions are built-inItfunctions
is a specific
in Cpurpose software.
programming. These

Input /Output Unit functions are defined in


Without header files.
system For example, Without application software
software,
 Random Access Memory (RAM): RAM is a volatile memory and loses its contents
.c

The input/output unit consists of devices used to transmit information between the
5  Thesystem can’t
printf() is arun.
standard library functionsystem always
to send runs. output to the
formatted
when the power is turned off. The circuit is so designed that any random location can
System software
output runs
on thewhen
es

external world and computer memory. The information fed through the input unit is stored screen (display screen). This function is defined in the stdio.h
be directly accessed without the need to scroll up or down the memory. The program to system is turned on and stop While application software runs as
in computer's memory for processing and the final result stored in memory can be header file.
be executed is loaded into RAM from the non-volatile backup memory. The processor 6 when system is turnedoff. per the user’s request.
om

ot

recorded or displayed on the output medium.  The sqrt() function calculates the square root of a number. The function is
reads instructions and data from the RAM, executes them and writes data back to the Compiler, Operating System, Photoshop, Microsoft Office
Examples for input devices: Mouse, Keyboard, Scanner, Joy Stick, Microphone,
defined in the math.h header file.
an

7 Interpreter
OCR (Optical Character Reader), MICR (Magnetic Ink Character Reader) RAM. Hence RAM is also known as the main memory of the computer. Everything from
.c

 The strlen() function calculates the length of a given string. The function is
Examples for output devices: Printer (Dot Matrix, Ink Jet, Laser, Line), Monitor the RAM is copied to the non-volatile backup memory before the computer is turned IIPE 8
al
es

defined in the string.h header file.


off. The two main types of RAM are Dynamic Ram (DRAM) and static RAM (SRAM).
For More Study Materials : www.keralanotes.com
r

Memory Unit
USER-DEFINED FUNCTIONS
ot

Each memory cell in a DRAM is made of one transistor and one MOS capacitor, which
ke

The Memory unit refers to the area where instructions and data are stored in a store one bit of data. However, this cell starts losing its charge and hence data can be Functions that we define ourselves to do certain specific task are referred as user-
om
an

computer. The processor reads instructions and data from the memory, executes them and retained for less than thousandth of a second. So it needs to be refreshed thousand times a defined functions.
writes the result back to it. Different forms of memory are used in a computer system. second, which takes up processor time. However, due to small size of each cell, one DRAM Advantages of user-defined functions
al

.c

They vary in their size, speed and location. Anything and everything in a computer is
can have large number of cells. Primary memory of most of the personal computers is
r

stored in the form of bits known as binary language or machine language. 8 bits make up a  The program will be easier to understand, maintain and debug.
ke

es

made of DRAM.
byte. The total number of bytes that a memory chip can hold at a time is termed as its size  Reusable codes that can be used in other programs
or capacity. Information is stored and processed as a group of bytes, called computer word. Each cell in SRAM is made of several transistors in a cross coupled flip flop
ot

The word length is specific for each processor. configuration that stores one bit. It retains its bit till the power supply is on and doesn’t  A large program can be divided into smaller modules. Hence, a large project can
be divided among many programmers.
n

 The Registers - Since the group of registers is in-built within the processor chip, they https://www.keralanotes.com/
need to be refreshed like DRAM. It also has shorter read-write cycles as compared to
EST102 Programming in C
la

are the fastest accessible units of memory by the processor. They are highly expensive DRAM. SRAM is used in specialized applications. Three parts of a user defined functions are:
Read Only Memory (ROM): ROM is a non-volatile memory and hence retains its contents
ra

and hence are limited in number. Some registers are used to store data while some are IIPE 3 1) Function Declaration or Prototype
reserved to store address. There are some general purpose registers as well. Size of the even when the computer is switched off. It is used for storing software that is rarely
For More Study Materials : www.keralanotes.com
ke

https://www.keralanotes.com/
registers depends on the processor. Accumulator is a registerEST102
https://www.keralanotes.com/
foundProgrammingchanged during the life of the system, sometimes known as firmware. Almost every
on all processors,
EST102 Programming in C
in C 2) Function Definition
which is mainly used to store the operand of an arithmetic operation. Program computer comes with a small amount of ROM containing the boot firmware which is EST102 Programming in C
3) Function Call
counter
counter (PC)
(PC) always
always stores
stores the
the address
address of the next
of the next instruction
instruction to
to be
be executed
executed by
by the
the essential for the boot-up. BIOS is a firmware used to perform hardware initialization
IIPE
processor.
processor.
2
during the booting process and to provide runtime services for operating systems and Function Declaration
int add(int,int,int);
https://www.keralanotes.com/
// function declaration
For More- Study Materials :high
www.keralanotes.com
 The
 The Cache
Cache Memory:
Memory: - It It is
is aa small
small piece
piece of
of high speed volatile
speed volatile memory
memory located
located closer
closer programs. The BIOS firmware comes pre-installed on the ROM and it is the first software A function
void main() prototype is simply the declaration of a function that specifies
to
to the
the processor
processor for
for fast
fast processing.
processing. Cache memory is
Cache memory is made
made ofof high
high speed
speed SRAMs.
SRAMs. ItIt to run when the computer is powered on. ROM memories have gradually evolved from function's name, parameters and return type. It doesn't contain function body. A
{
acts
acts as
as aa buffer
buffer between
between the
the CPU
CPU and
and the RAM. It
the RAM. It holds
holds frequently
frequently accessed
accessed data
data and
and fixed read-only memories to memories that can be programmed and then re-programmed. int x=10,y=20,z=30,res;
function prototype gives information to the compiler that the function may later be
instructions
instructions so
so that
that they
they can
can be
be easily
easily supplied to the
supplied to the CPU
CPU when
when requested
requested again.
again.Cache
Cache res = add(x,y,z); // function call EST102 Programming in C
 ROM (Read Only Memory) used in the program.
printf(“Result=%d”,res);
https://www.keralanotes.com/
m

memory
memoryis
isused
used to
to reduce
reduce the
the average
average time to access
time to access data
data from
from the
the Main
Main memory.
memory.
}
 PROM (Programmable Read Only Memory) return_type function_name( parameter list );
 Primary
 Primary Memory:
Memory: -- The
The memory
memory chips that the
the processor
processor can
can directly
directly access
access are
are
co

chips that
Note:
referred
referredto
to as
as primary
primary memory.
memory. The
The three types of
three types of primary
primary memory
memory are RAM,ROM
are RAM, ROMand
and  EPROM (Erasable Programmable Read Only Memory). Syntaxint add(int a, int b, int c) // function definition
CMOS.
CMOS. RAM
RAM is
is volatile
volatile whereas
whereas ROM
ROM as CMOS are
are non-volatile
non-volatile memories.
memories. They
They are
are { If function definition is written after main, then only we write prototype
s.

as CMOS
m

 EEPROM (Electrically Erasable Programmable Read Only Memory) int sum; in global declaration section
declaration
metal
metaloxide
oxidesemiconductor
semiconductor memory
memory cells
cells built on silicon
built on silicon based
based ICs.
ICs. IIPE 2
sum = a+ b + c;
te
co

 If function definition is written above the main function then ,no need to
 Complementary Metal Oxide Semiconductor (CMOS): CMOS is a technology used to return sum; //return statement
 Random
 Random Access
Access Memory
Memory (RAM): RAM is a volatile memory
memory and
and loses
loses its
its contents
contents For More Study Materials : www.keralanotes.com
} write prototype declaration
no

produce integrated circuits, but the term is commonly used to refer to the CMOS
s.

when
when the
the power
power is
is turned
turned off.
off. The circuit is so designed
designed that
that any
any random
random location
location can
can
m

be
bedirectly
directlyaccessed
accessed without
without the need to scroll up or down
down the
the memory.
memory. The
Theprogram
programto
to memory on the mother board. It is known as non-volatile RAM (NVRAM). It is powered Function Definition
Return Statement
te

co
la

be
be executed
executed is
is loaded
loaded into
into RAM
RAM from the non-volatile backup
backup memory.
memory. The
The processor
processor by an onboard battery and stores system setting configurations that are required at The return
A function statement
definition terminates theconsists
in C programming execution
of aoffunction
a function and and
header returns a value
a function
no

boot time . In case the battery runs out, the CMOS is reset and loses all custom settings to the calling function. The program
of returncontrol is transferred to the calling function after
ra

reads
reads instructions
instructions and
and data
data from the RAM, executes them
them and
and writes
writes data
data back
back to
to the
the body. Function header consist type,function name,arguments(parameters).
s.

RAM.
RAM.Hence
Hence RAM
RAM is
is also
also known
known as the main memory of the
the computer.
computer. Everything
Everythingfrom
from including the system clock. The information needs to be restored after replacing the the
 return
Returnstatement.
Type: A function may return a value. The return_type is the data type of
la

ke

te

the
the RAM
RAM is
is copied
copied to
to the
the non-volatile
non-volatile backup memory before
before the
the computer
computer is
is turned
turned battery. In value
the above example, the value the sum perform
of functions variable the
is returned to the main
the the function returns. Some desired operations
ra

om

off.
off.The
Thetwo
twomain
main types
types of RAM are Dynamic Ram (DRAM)
of RAM (DRAM) and static RAM
and static RAM(SRAM).
(SRAM). function. The res variable in the In
main() function is assigned this value.
keyword void
no

Secondary Memory: - Primary memory has limited storage capacity and is volatile. without returning a value. this case, the return_type is the
Eachmemory
Each memory cell
cell in
in aa DRAM
DRAM is made of one transistor
transistor and
and one
one MOS
MOS capacitor,
capacitor,which
which
ke

Secondary memory overcomes this limitation by providing permanent storage of data and  Function
Formal Name:
and Actual The actual name of the function. The function name and the
Parameters
store one
store one bit
bit of
of data.
data. However,
However, this cell starts losing its charge
charge and
Downloaded and hence
hence data
data can be
canfrom
be Ktunotes.in
la

.c

in bulk quantity. They are the slowest and cheapest form of memory. It cannot be accessed parameter
There are list together
different constitute
ways in whichtheparameters
function signature.
can be passed into and out of
retainedfor
retained for less
less than
than thousandth
thousandth of a second. So it needs to be
be refreshed
refreshed thousand
thousandtimes
timesaa
directly by the CPU. Programs need to be moved to primary memory in order to be  Parameters: A parameter is like a placeholder. When a function is invoked, you
EST102 Programming in C

Disadvantages of an Array https://www.keralanotes.com/


• It allows us to enter only fixed number of elements into it. We cannot alter the size of
the array once array is declared. Hence if we need to insert more number of records
than declared then it is not possible. We should know array size at the compile time
itself.
• Inserting and deleting the records from the array would be costly since we add /
EST102 Programming in C
delete the elements from the array, we need to manage memory space too.

Disadvantages of an Array https://www.keralanotes.com/


• It does not verify the indexes while compiling the array. In case there is any indexes

• It allows us to enter only fixed number of elements into it. pointed which
We cannot alteristhe
more
sizethan
of the dimension specified, then we will get run time errors
the array once array is declared. Hence if we need to insertrather
morethan identifying
number them at compile time.
of records
Example:
than declared then it is not possible. We should know array size at the compile time
itself. int a[3]={1,2,3}
m

printf("%d",A[3]);
• Inserting and deleting the records from the array would be costly since we add /
EST102 Programming in C
co

Output:
delete the elements from the array, we need to manage memory space too. 3245431 (Garbage Value)
• It doeschar
notstr[]="Hello
verify the World"; https://www.keralanotes.com/
indexes while compiling the array. In1.case Write a program
there to read and display an array of size n.
is any indexes
.

int len=strlen(str); #include<stdio.h>


pointed which is more than the dimension specified, then we will get run time errors
es

int size=sizeof(str); void main()


rather than identifying them at compile time.
printf("Value=%d",len*size); {
ot

Example: int n,A[20],i;


}
int a[3]={1,2,3} printf("Enter the size of Array:");
an

len value will the length of the string which is 11. But size value will be 12 including the
m com

scanf("%d",&n);
printf("%d",A[3]);
end of character. EST102 Programming in C
for(i=0;i<n;i++)
Output:
Output 3245431 (Garbage Value)
al

1. Write a program to read and display an array of size n.


Value=132
{ Sum=50
printf("\nEnter the number:");
https://www.keralanotes.com/
r

scanf("%d",&A[i]); 4. Write a program to multiply two matrices


.

PROGRAM
ke

#include<stdio.h>
s. es

} To multiply two matrices, the number of columns of the first matrix should be
strcat
void main()
#include<stdio.h> { for(i=0;i<n;i++) equal to the number of rows of the second matrix.
It concatenates two strings and returns the concatenated string.
ot

struct employee int n,A[20],i; {


Syntax: strcat(string1,string2) – concatenate string1 with string2. printf("%d\t",A[i]);
{ printf("Enter the size of Array:"); #include <stdio.h>
co
an

#include <stdio.h> }
int employeeID; scanf("%d",&n); void main()
char ename[25]; #include <string.h>
for(i=0;i<n;i++) } {
OUTPUT int i,j,k,m, n, p, q,sum = 0;
ra ral

float salary; {void main()


}; { Enter the size of Array: 5 int A[10][10], B[10][10], C[10][10];
te

printf("\nEnter the number:");


char s1[10] = "Hello"; Enter the number:10 printf("Enter number of rows and columns of first matrix\n");
void main() scanf("%d",&A[i]);
ke

EST102
theProgramming in C scanf("%d%d", &m, &n);
no

char s2[10] = "World"; Enter number:20


{ }strcat(s1,s2); printf("Enter number of rows and columns of second matrix\n");
Enter the number:30
struct employee e1[100]; for(i=0;i<n;i++)
https://www.keralanotes.com/
str1[i]=str2[j];%s", s1);
printf("After concatenation: scanf("%d%d", &p, &q);
m

Enter the number:40


la

int n,i; {} } if (n != p)
printf("Enter the total number of employees:\n"); Output:printf("%d\t",A[i]);
str1[i]='\0'; Enter the number:50 printf("The multiplication isn't possible.\n");
co

scanf("%d",&n); printf("\nOutput:
}After concatenation: %s",str1);
HelloWorld else
} IIPE 2
ke

printf("ENTER THE EMPLOYEE DETAILS:\n"); } {


s.

for(i=0;i<n;i++) OUTPUT printf("Enter elements of first matrix\n");


Program to concatenate two strings without using string handling function
for (i = 0; i < m; i++)
te

{ strcpy
Enter the size of Array: 5
#include <stdio.h> For More Study Materials : www.keralanotes.com
for (j = 0; j < n; j++)
printf("Enter the employeeID :"); Enter the number:10
void It copies the string str2 into string str1, including the end character (terminator
main()
no

scanf("%d", &A[i][j]);
scanf("%d",&e1[i].employeeID); Enter the
{ number:20
char ‘\0’). printf("Enter elements of second matrix\n");
printf("Enter the employee name:"); Enter the number:30
char str1[50], str2[25], i, j; for (i = 0; i < p; i++)
Syntax: strcpy(string1,string2) - copy the content of string2 to string1
la

scanf("%s",e1[i].ename); printf("\nEnter
Enter the number:40 first string: "); for (j = 0; j < q; j++)
#include <stdio.h>
gets(str1);
printf("Enter the salary:"); Enter the number:50
ra

scanf("%d", &B[i][j]);
#include <string.h>
printf("\nEnter second string: ");
scanf("%f",&e1[i].salary); for (i= 0; i < m; i++)
void main()
gets(str2);
ke

} IIPE 2 {
{ for(i=0; str1[i]!='\0'; i++);
om

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


char s1[30];
for(j=0; str2[j]!='\0'; j++, i++) EST102 Programming in C
{
printf("THE EMPLOYEE DETAILS ARE:\n"); char
{ s2[30] = "Hello World";
For More Study Materials : www.keralanotes.com C[i][j]=0;
for(i=0;i<n;i++) strcpy(s1,s2);
str1[i]=str2[j];
https://www.keralanotes.com/
.c

for (k = 0; k < p; k++)


{ IIPE printf("String
} s1: %s", s1); 13
} {
es

str1[i]='\0';
printf("%d %s %f \n",e1[i].employeeID,e1[i].ename,e1[i].salary); Output:printf("\nOutput: %s",str1); C[i][j]= C[i][j] + A[i][k]*B[k][j];
} String
} For More
s1 : Hello World Study Materials : www.keralanotes.com }
ot

}
Program to copy a string to another without using string handling function
} OUTPUT }
n

strcpy
#include<stdio.h> printf("Product of the matrices:\n");
Enter the total number of employees:
la

void main() for (i = 0; i< m; i++)


3 It copies the string str2 into string str1, including the end character (terminator
ENTER THE EMPLOYEE DETAILS: { { EST102 Programming in C
ra

Enter the employeeID :111 char ‘\0’).


char a[50], b[50]; for (j = 0; j< q; j++)
Enter the employee name:Akash
Enter the salary:20 000
Syntax:int
strcpy(string1,string2)
i=0; - copy the content of string2 to string1 {
https://www.keralanotes.com/
ke

printf(“Enter IIPE 22
Enter the employeeID :112 #include <stdio.h> string1:”); printf("%d\t", C[i][j]);
Enter the employee name:Aishwarya gets(a);
Enter the salary:30 000 #include <string.h> }
for(i=0;a[i]!=‘\0’;i++)
void main() printf("\n");
Enter the employeeID :113
{
For More Study Materials : www.keralanotes.com
Enter the employee name:Sam { }
om

Enter the salary:40 000 b[i]=a[i];


THE EMPLOYEE DETAILS ARE: char s1[30]; }
111 Akash 20.000000
} s2[30] = "Hello World";
char }
112 Aishwarya 30.000000 b[i]=‘\0’;
strcpy(s1,s2);
.c

113 Sam 40.000000 } printf("String s1: %s", s1); PREVIOUS YEAR UNIVERSITY QUESTIONS
} 1. Explain the different ways in which you can declare & initialize a single dimensional
es

strcmp
Output: array. [KTU, MODEL 2020]
String s1 : Hello World 2. Write a C program to read a sentence through keyboard and to display the count of
ot

Program to copy a string to another without using string handling function white spaces in the given sentence. [KTU, MODEL 2020]
3. Write a C program to check whether a given matrix is a diagonal matrix. [KTU,
n

#include<stdio.h>
Downloaded from Ktunotes.in MODEL 2020]
la

void main()
IIPE 14 4. Write a C program to perform bubble sort. [KTU, MODEL 2020], [KTU, JULY 2017],
{
EST102 Programming in C

rev[j]=str[i];
j++;
https://www.keralanotes.com/
i--;
}
rev[j]='\0';
printf("\nReverse=%s",rev);
}
Output
Enter the string: hello
Reverse=olleh

3. Write a program to check whether a string is palindrome or not without using in


built functions. PROGRAM
#include<stdio.h>
#include<string.h> #include <stdio.h>
void main() void main()
m

{ {
char a [25];
co

char str[20];
int len,i,j,flag; int v=0,c=0,S=0;
printf ("Enter the string :");
printf("Enter the string:");
s.

gets (a);
gets(str);
te

// Code to find string length


for (int i=0; a[i]!= '\0'; i++)
for(len=0;str[len]!='\0';len++);
{
no

// Code to check the Palindrome


if(a[i] == 'a'||a[i]=='e'|| a[i]=='i' || a[i]=='o'|| a[i]=='u'|| a[i]=='A'|| a[i]=='E' || a[i] == 'I' || a[i]=='O' ||
flag=0;
a[i]== 'U')
for(i=0;i<len/2;i++)
la

{
{ v=v+1;
ra

if(str[i] != str[len-i-1]) }
{
ke

flag=1; else if (a[i]==' ')


break; {
} S=S+1;
https://www.keralanotes.com/

} }
27

if(flag == 0)
EST102 Programming in C

for loop is similar to while, for statements are often used to process lists such a

{ else
printf("\nPalindrome"); {
} c = c+1;
For More Study Materials : www.keralanotes.com

else }
m

{ }
printf("\nNot Palindrome"); printf("Number of vowels %d\n",v);
co

} printf("Number of white space %d\n",S);


printf("Number of consonants %d\n",c);
s.

}
}
// To count the number of digits in the number

t e

IIPE
no

17
rev = sum + pow(temp,count);

for( expression1; expression2; expression3)


printf("\nNot Armstrong");
a

For More Study Materials : www.keralanotes.com


printf("\nArmstrong");
int n,sum=0,temp,org,count=0;

Basic syntax of for loop is as follows:


al

OUTPUT
printf("Enter the number:");

Enter the string :aeiou abc ghf


r
ke
temp = n%10;

Number of vowels 6
n = n/10;

Number of white space 2


scanf("%d",&n);

count++;
n=n/10;

Enter the number:153


if( org == sum)
while ( n > 0 )
while( n > 0)

Number of consonants 5
Armstrong or not.

#include <math.h>
#include <stdio.h>

range of numbers.
org=n;
void main()

else

Armstrong
OUTPUT

for loop
{

IIPE
{

Downloaded from Ktunotes.in

You might also like