0% found this document useful (0 votes)
14 views14 pages

46insert in Linear Array

This document discusses inserting an element into a linear array at a specified position in C programming. It provides the objective, introduction to arrays and linear arrays, problem statement, sample code to insert an element, and sample output.

Uploaded by

Kamal Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views14 pages

46insert in Linear Array

This document discusses inserting an element into a linear array at a specified position in C programming. It provides the objective, introduction to arrays and linear arrays, problem statement, sample code to insert an element, and sample output.

Uploaded by

Kamal Hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Dhaka Commerce College

Department of Computer Science and


Engineering

Presented by: Course Teacher:


Nazmul Hasan Munna
Md. Hemaet Uddin
Roll:- 46
Lecturer
Department of Computer Science and Engineering
Department of Computer Science and Engineering
Dhaka Commerce College
Outline
 Objective
 Introduction
 Problem Statement
 Programming Code
 Output
 Objective
Insert an element in array at specified position
Introduction
What is array?
An array is a collection of data item, all of the same type, accessed using a
common name.

Syntax : data_type array_name[array size];


Types of array
 One Dimensional Array
 Two Dimensional Array
 Multi- Dimensional Array
Problem statement

How to write a program to


insert an element into linear
array
What is linear array
A linear array is a list of finite numbers of elements stored in
the memory. In a linear array, we can store only
homogeneous data elements. Elements of the array form a
sequence or linear list that can have the same type of data.
 A program to insert an element into the linear array

#include<stdio.h>
void main()
{
int array[100];
int i,size,number,position;
printf("Enter the size of Array:");
scanf("%d",&size);
printf("Enter Element in an Array:");
for(i=0;i<size;i++)
{
scanf("%d",&array[i]);
}
printf("Enter the Element to Insert:");
scanf("%d",&number);
printf("Enter the Position of Element:");
scanf("%d",position);
if(position>size+1||position<=0)
{
printf("Enter Value Position between1to%d",size);
}
else
{
for(i=size;i>=position;i--)
{
array[i]=array[i-1];
}
array[position-1]=number;
size++;
printf("Array Element After Insertion:");
for(i=0;i<size;i++)
{
printf("%d\t",array[i]);
}

}
}
result
Enter the size of Array: 5
Enter Element in an Array: 8 9 7 3 1
Enter the Element to Insert: 5
Enter the Position of Element: 2
After Elements After Insertion: 8 9 5 7 3 1
Thank you

You might also like