Delete an Element from Specified Location from Array : C Program

Computer Science » C Program » Delete an Element from Specified Location from Array

Program :

#include<stdio.h>
 
int main() 
{
   int arr[30], num, i, loc;
 
   printf("nEnter no of elements : ");
   scanf("%d", &num);
 
   //Read elements in an array
   printf("nEnter %d elements : ", num);
   for (i = 0; i < num; i++) {
      scanf("%d", &arr[i]);
   }
 
   //Read the location
   printf("nLocation of the element to be deleted : ");
   scanf("%d", &loc);
 
   /* loop for the deletion  */
   while (loc < num) {
      arr[loc - 1] = arr[loc];
      loc++;
   }
   num--;  // No of elements reduced by 1
 
   //Print Array
   for (i = 0; i < num; i++)
      printf("n %d", arr[i]);
 
   return (0);
}

Output :

Enter no of elements : 5
Enter 5 elements : 
10 20 30 40 50
Location of the element to be deleted : 3
 10
 20
 40
 50
Subject Name : Computer Science
Exam Name : IIT GATE, UPSC ESE, RRB, SSC, DMRC, NMRC, BSNL, DRDO, ISRO, BARC, NIELIT
Posts Name : Assistant Engineer, Management Trainee, Junior Engineer, Technical Assistant
Computer Science Books

GATE 2023 Total InfoENGG DIPLOMAUGC NET Total Info
IES 2023 Total InfoPSUs 2022 Total InfoCSIR UGC NET Total Info
JAM 2023 Total InfoM TECH 2023 Total InfoRAILWAY 2022 Total Info

Related Posts

  • Delete Duplicate Elements in an Array : C ProgramComputer Science » C Program » Delete Duplicate Elements in an Array  Program : [php]#include<stdio.h> int main() { int arr[20], i, j, k, size; printf("nEnter array size : "); scanf("%d", &size); printf("nAccept numbers : "); for (i = 0; i < size; i++) scanf("%d", &arr[i]); printf("nArray with unique list : "); for (i = 0; i < size; i++) { for (j = i + 1; j < size;) { if (arr[j] == arr[i]) { for (k = j; k < size; k++) { arr[k] = arr[k + 1]; } size--; } else j++; } } for (i = 0; i < size; i++) { printf("%d ", arr[i]); } return (0); }[/php] Output : [php]Enter array size : 5 Accept numbers : 1 2 3 4 3 Array with unique list : 1 2 3 4 [/php]
    Tags: program, delete, array, computer, science, output, programs
  • C Program ExamplesComputer Science » C Program » C Program Examples "How to print hello, world! using c program ? How to find area of a circle using c program ? How to find smallest element in an array using c program ? You all must have this kind of questions in your mind. Below article will solve this puzzle of yours. Just take a look.”  - Here we have listed all the programs in C programming language, categorised under different progamming concepts like Basic, Area, Mathematical, Number, Array etc. Check the respective category to view all the programs under that category. C Programs - Basic C Programs C Programs - Number Programs C Programs - Area Programs C Programs - Mathematical Programs C Programs - Array Programs C Programs - Electrical Programs C Programs - Pyramid Programs
    Tags: programs, program, computer, science
  • Print Alternate Numbers in an Array : C ProgramComputer Science » C Program » Print Alternate Numbers in an Array  Program : [php] int main() { int array[9]; int i; printf("Enter the element of the array : "); for (i = 0; i < 9; i++) scanf("%d", &array[i]); printf("nAlternate elements of the entered array : n"); for (i = 0; i < 9; i += 2) printf( "%dn", array[i]) ; }[/php] Output : [php]Enter the element of the array : 1 2 3 4 5 6 7 8 9 Alternate elements of the entered array : 1 3 5 7 9[/php]
    Tags: program, array, computer, science, output, programs
  • Find the Number of Elements in An Array : C ProgramComputer Science » C Program » Find the Number of Elements in An Array Program : [php]#include <stdio.h> int main() { int array[] = {10, 20, 30, 40, 50, 60, 70,80,90,100}; int n,m; n = sizeof(array); m = n/sizeof(int); printf("Size of the given array is : %d", m); return 0; }[/php] Output : [php]Size of the given array is : 10[/php]
    Tags: program, array, computer, science, output, programs
  • Calculate Addition of All Elements in Array : C ProgramComputer Science » C Program » Calculate Addition of All Elements in Array Program : [php]#include&lt;stdio.h&gt; int main() { int i, arr[50], sum, num; printf("nEnter number of elements :"); scanf("%d", &amp;num); //Reading values into Array printf("nEnter the values :"); for (i = 0; i &lt; num; i++) scanf("%d", &amp;arr[i]); //Computation of total sum = 0; for (i = 0; i &lt; num; i++) sum = sum + arr[i]; //Printing of all elements of array for (i = 0; i &lt; num; i++) printf("na[%d]=%d", i, arr[i]); //Printing of total printf("nSum of all elements : %d", sum); return (0); }[/php] Output : [php]Enter number of elements : 4 Enter the values : 10 20 30 40 a[0]=10 a[1]=20 a[2]=30 a[3]=40 Sum of all elements : 100[/php]
    Tags: program, array, computer, science, output, programs

LEAVE A REPLY

Please enter your comment!
Please enter your name here