Members BookmarksPolls Fresher Jobs Funny Photos B.Tech Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

Advertisements


website counter



Program to insert an element in 1-Dimensional array


Posted Date: 27 May 2008    Resource Type: Articles/Knowledge Sharing    Category: E-Books

Posted By: Vidya       Member Level: Diamond
Rating:     Points: 1



Program to insert an element in 1-Dimensional array

#include
#include
#define SIZE 20
/********** Function Declaration begins **********/
int insert(int[],int,int,int);
void traverse(int[],int);
/********** Function Declaration ends **********/
void main()
{
int i=0,A[SIZE],n,pos,item;
clrscr();
printf(“\n\n\t\t Program to insert element in 1-Dimensional array:”);
printf(“\n\n\t\tHow many number you want to store in the array:”);
scanf(“%d”,&n);
while(i {
printf(“\nEnter value A[%d]:”,i);
scanf(“%d”,&A[i]);
i++;
}
traverse(A,n);
printf(“\nEnter the index to insert new number:”);
scanf(“%d”,&pos);
printf(“\nEnter the number:”);
scanf(“%d”,&item);
n = insert(A,n,pos,item);
traverse(A,n);
getch();
}

/********** Traversing array elements **********/
/********** Function Definition begins **********/
void traverse(int A[], int n)
{
int i=0;
printf(“\n\n\t\t elements of array are:\n”);
while(i {
printf(“A[%d]:”,i);
printf(“%d\n”,A[i]);
i++;
}
printf(“\n”);
}
/********** Function Definition ends **********/

/********** inserting array element **********/
/********** Function Definition begins **********/
int insert(int A[], int n, int pos, int item)
{
int i;
for(i=n;i>=pos;i—)
A[i+1] = A[i];
A[pos] = item;
n= n+1;
return n;
}
/********** Function Definition ends **********/
? OUTPUT
Program to insert an element from 1-Dimensional array:
How many number you want to store in the array:6

Enter value A[0]:11
Enter value A[1]:22
Enter value A[2]:33
Enter value A[3]:44
Enter value A[4]:55
Enter value A[5]:66
elements of array are:
A[0]:11
A[1]:22
A[2]:33
A[3]:44
A[4]:55
A[5]:66

Enter the index to insert new number: 3
Enter the number:88
elements of array are:
A[0]:11
A[1]:22
A[2]:33
A[3]:88
A[4]:44
A[5]:55
A[6]:66





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Algorithm Ebooks
Previous Resource: LINKS FOR DOWNLOADING UNLIMITED BOOKS
Return to Discussion Resource Index
Post New Resource
Category: E-Books


Post resources and earn money!
 
Related Resources


Contact Us    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.