C program to accept an array of integers and delete the specified integer from the list

by Nideesh C on April 13, 2011 · 0 comments

in C Programming




/*  C program to accept an array of integers and delete the specified integer from the list  */

#include <stdio.h>

void main()
{
int  vectx[10];
int  i, n, pos, element, found = 0;

printf(“Enter how many elements\n”);
scanf(“%d”, &n);

printf(“Enter the elements\n”);
for(i=0; i<n; i++)
{
scanf(“%d”, &vectx[i]);
}

printf(“Input array elements are\n”);
for(i=0; i<n; i++)
{
printf(“%d\n”, vectx[i]);
}

printf(“Enter the element to be deleted\n”);
scanf(“%d”,&element);

for(i=0; i<n; i++)
{
if ( vectx[i] == element)
{
found = 1;
pos = i;
break;
}
}

if (found == 1)
{
for(i=pos; i< n-1; i++)
{
vectx[i] = vectx[i+1];
}

printf(“The resultant vector is \n”);
for(i=0; i<n-1; i++)
{
printf(“%d\n”,vectx[i]);
}
}
else
printf(“Element %d is not found in the vector\n”, element);

}         /* End of main() */

/*—————————————————
Output

Run 1
Enter how many elements
5
Enter the elements
30
10
50
20
40
Input array elements are
30
10
50
20
40
Enter the element to be deleted
35
Element 35 is not found in the vector

Run 2
Enter how many elements
4
Enter the elements
23
10
55
81
Input array elements are
23
10
55
81
Enter the element to be deleted
55
The resultant vector is
23
10
81

——————————————————–*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to input N numbers (integers or reals) and store them in an array. Conduct a linear search for a given key number and report success or failure in the form of a suitable message
  2. C program to read N integers and store them in an array A, and so find the sum of all these elements using pointer. Output the given array and and the computed sum with suitable heading
  3. C Program to accept N integer number and store them in an array AR. The odd elements in the AR are copied into OAR and other elements are copied into EAR. Display the contents of OAR and EAR
  4. C program to insert a particular element in a specified position in a given array
  5. C program to accept N numbers sorted in ascending order and to search for a given number using binary search. Report success or failure in the form of suitable messages

Leave a Comment

Previous post:

Next post: