write a program to insert an element into an array

Answer Posted / antony

/* Program to insert element into array */
#include<stdio.h>
#include<conio.h>
int n,pos;
void main()
{
int arr[50],i,ch;
void insert (int *);
void update (int *);
void delete (int *);
void search (int *);
void display (int *);
//clrscr();
printf("How Many Elements you will insert:-");
scanf("%d",&n);
printf("\n\tEnter Elements into Array");
for(i=0;i<n;i++)
scanf("\t%d",&arr[i]);
while(1)
{
printf("\n1.insert\n");
printf("2.Delete\n");
printf("3.Search\n");
printf("4.Display\n");
printf("5.Exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1: insert(arr); display(arr); break;
case 2: delete(arr); display(arr); break;
case 3: search(arr); break;
case 4: display(arr); break;
case 5: exit(1);
}
}
getch();
}
void insert(int *arr)
{
int num,i;
printf("\nEnter the position");
scanf("%d",&pos);
if(pos==0 || pos>=n)
{
printf("Invalid position");
}
else
{
printf("\nEnter the number you want to insert into an array");
scanf("%d",&num);
/*shift the existing elements*/
for(i=n;i>=pos;i--)
arr[i]=arr[i-1];
arr[pos-1]=num;
}
}
void delete(int *arr)
{
int pos,i;
printf("\nEnter the position");
scanf("%d",&pos);
if(pos==0 || pos>=n)
{
printf("Invalid position");
}
else
{
for(i=pos-1;i<n;i++)
arr[i]=arr[i+1];
n--;
}
}
void display(int *arr)
{
int i;
printf("\nCurrent Array elements are:");
for(i=0;i<n;i++)
{
printf("\n%d",arr[i]);
}
}
void search(int *arr)
{
int i=0,tmp,tmp2=0;
printf("\nEnter the number u want to search:");
scanf("%d",&tmp);
for (i=0;i<=n;i++)
{
if(tmp==arr[i])
{
tmp2=i+1;
}
}
if (tmp2!=0)
{
printf("The element present in the position is: %d",tmp2);
}
else
{
printf("The element not present");
}
}

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which command properly allocates memory a) char *a=new char[20]; b) char a=new char[20]; c) char a=new char(20.0);

620


What are smart pointers?

672


What is a map in c++?

587


What is c++ iterator?

648


A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9 percent of their gross sales for that week. For example, a saleperson who sells $5000 worth of merchandise in a week receives $200 plus 9 percent of $5000, or a total of $650. You have been supplied with a list of items sold by each salesperson. The values of these items are as follows: Item Value A 239.99 B 129.75 C 99.95 D 350.89 Write a program that inputs one salesperson's items sold in a week (how many of item A? of item B? etc.) and calculates and displays that salesperson's earnings for that week.

3415






Can there be at least some solution to determine the number of arguments passed to a variable argument list function?

608


What is a singleton c++?

551


Is it possible to use a new for the reallocation of pointers ?

601


What is problem with overriding functions?

611


What's c++ used for?

602


What are move semantics?

675


Visual Basic 6 All the questions are compulsory. The first five questions shall be of 16 marks each and the last question shall be of 20 marks. Q1. A. Discuss the various types of variables. B. How to control the file? Q2. A. How the image application? B. Write short notes on trees structures work. Q3. A. How to load and unload child forms. B. When should we use recursive programming Q4. A. Write short notes on "The ole control's shortcut menu" B. How to test the AX stat class Q5. A. How to use advanced data-bound controls. B. Write notes on manipulating the recordset object Q6. A. What is script control? B. How to down load image properties. C. What is meant by building a recordset. PROJECT 2002 All the questions are compulsory. The first five questions shall be of 16 marks each and the last question shall be of 20 marks. Q1. A. How can we determine performance standards? B. Write note on chaining views. Q2. A. Discuss the working with task in Gantt chart view. B. Explain the creation project schedule. Q3. A. What is understand in resource tracking? B. Write short notes on Caturing Baseline. Q4. A. How to customize workgroup message? B. How to use hyperlink? Q5. A. Explain the installation of project server? B. Discuss the working with to-do lists. Q6. A. Explain the working of templates? B. What is visual basic? C. Write shortnotes on user forms. PROGRAMMING WITH C++ All the questions are compulsory. The first five questions shall be of 16 marks each and the last question shall be of 20 marks. Q1. A. What is unary operator? List out the different operators involved in the unary operator. B. What is an adjust field format flag? Q2. A. Distinguish between a # include and #define. B. Can a list of string be stored within a two dimensional array? Q3. A. Explain how a pointer to function can be declared in C++? B. List the merits and demerits of declaring a nested class in C++? Q4. A. What are the syntactic rules to be avoid ambiguity in multiple inheritence? B. Explain the operation of overloading of an assignment operator. Q5. A. Explain how the virtual base class is different from the conventional base classes of the opps. B. Explain how an exception handler is defined and invoked in a Program. Q6. A. What is a binary file? List the merits and demerits of the binary file usagein C++. B. Write short notes on Text Manipulation Routines. C. Write bites in Turbo c++ Header ("Include") Files. Java All the questions are compulsory. The first five questions shall be of 16 marks each and the last question shall be of 20 marks. Q1. A. Write note on "The class path Environment Variable". B. Which are different kinds of source code? Q2. A. How to create an interface? B. Why convert an applet to an application? Q3. A. How to use Media tracker Class. B. How to use string tokenizer class. Q4. A. Explain the overview of UDP messaging. B. Difference between SQL Exception class and SQL Warning class. Q5. A. How to create com object in Java? B. Write short notes on "The properties class" Q6. A. When object is created and destroyed? B. Explain the JDB in depth & command line. C. Write short notes on Web Sites. MULTIMEDIA All the questions are compulsory. The first five questions shall be of 16 marks each and the last question shall be of 20 marks. Q.1 Write a C language program to perform CCITT group 3 compression. If possible, scan some images and use your program to compress the images. What kind of compression did you achieve? Q2. How does a magneto-optical technology differ from WORM technology? Explain the differences in the manner in which you would use them for a multimedia system. Q3. What network considerations would you contemplate in designing an enterprise-wide multimedia system which supports fully distributed integrated messaging, sharing of corporate multimedia information databases, and custom business process applications? Q4. Explain the difference between the various types of multimedia object servers. How would you set up hierarchical storage for a large distributed organization? Q5. Explain the role of each type of server required in a multimedia system and the type of storage media that should be used for it. Q6. How do your decisions affect the design? Would different decisions on network technologies and object server technologies result in a different solution? OPERATING SYSTEM All the questions are compulsory. The first five questions shall be of 16 marks each and the last question shall be of 20 marks. Q1. What is an interrupt? How are multiple interrupts dealt with? Q2. Explain the difference between a MONOLITHIC KERNAL and a MICROKERNAL? Q3. List reasons why a Mode switch between threads may be cheaper than a Mode switch between processes. Q4. What is the difference among deadlock avoidance, detection and prevention? Q5. What items of information about a task might be useful in real time scheduling? Q6. Discuss some of the reasons for implementing process migration ? How is the process address space handled during process migration? WEB APPLICATIONS All the questions are compulsory. The first five questions shall be of 16 marks each and the last question shall be of 20 marks. Q1. Explain Java script in Web pages? Q2. Explain the advantages of Java script. Q3. Write the Properties of HTML object. Q4. How a JavaScript enabled browser handles the document object? Q5. What are cookies? Q6. Explain the process of controlling the Program flow in Pearl.

4709


Is it possible to have a recursive inline function in c++?

560


Is c++ vector a linked list?

552


List the merits and demerits of declaring a nested class in C++?

611