CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
Interview Success Kit - Get Success in Job Interviews Interview Success Kit - 30,000 Interview Que. & Ans.
Covers 30,000+ Interview Questions asked in actual MNC Interviews - all with model answers.

Sponsored Links

Interview Questions
Our Services

INTERVIEW QUESTIONS C ARRAYS IN C DETAILS
Question :

Write a program to delete an element from an array?

Posted by: pratyaksh on 8/19/2013

Contact pratyaksh Contact pratyaksh

Category Arrays in C Interview Questions
Rating (3.4) By 35 users
Added on 8/19/2013
Views 1076
Rate it!


Answers:

Source: CoolInterview.com

Programming's = loads of fun!!!!!!!
#include <stdio.h>
#include <conio.h>
#define size 10
void main()
{ int a[size],del,j,i;
clrscr();
for(i=0;i<size;i++)
{j=i+1;
printf("
Enter the %d element of array",j);
scanf("%d",&a[i]);}
printf("
Enter the element to be deleted");
scanf("%d",&del);
del--;
for(i=del;i<size-1;i++)
a[i]=a[i+1];
a[size-1]=0;
printf("
Element has been deleted");
printf("
Array now is.....
");
for(i=0;i<size;i++)
printf("%d ",a[i]);
getch();
}

Another way of writing the program is to just assign value zero to the specified element.

#include <stdio.h>
#include <conio.h>
#define size 10
void main()
{ int a[size],del,j,i;
clrscr();
for(i=0;i<size;i++)
{j=i+1;
printf("
Enter the %d element of array",j);
scanf("%d",&a[i]);}
printf("
Enter the element to be deleted");
scanf("%d",&del);
/*Corresponding element assigned value zero*/
a[--del]=0;
for(i=0;i<size;i++)
printf("%d ",a[i]);
getch();
}

Stay COOOooolllllllllllll!!!!!!!

Source: CoolInterview.com



Posted by: Pranjal Gururani

Contact Pranjal Gururani Contact Pranjal Gururani

Source: CoolInterview.com

#include <stdio.h>
#include <stdlib.h>


/* Program to remove one element from array*/
int main()
{
int * array1;

int size1;
printf("What is original Size of Array
");
scanf("%d", &size1);

array1 = (int*)malloc(size1 * sizeof(int ));

if(array1 == NULL)
{
fprintf(stderr, "out of memory
");
exit;
}

for (int i = 0; i< size1; i++)
{
array1[i] = i;
printf("Element %d : %d
",i, array1[i]);
}





int number;
printf("Which element do you wish to remove
");
scanf("%d", &number);

for (i = number; i< size1-1; i++)
{
array1[i] = array1[i+1];
}

printf("





");

realloc(array1,(size1-1) * sizeof(int ));

for (int i = 0; i< size1-1; i++)
{

printf("Rearranged Element %d : %d
",i, array1[i]);
}

free(array1);


return 0;
}
Source: CoolInterview.com



Posted by: rn

Contact rn Contact rn

Source: CoolInterview.com

#include <stdio.h>
//#include <conio.h>
#include"stdafx.h"
#include"malloc.h"
//#define size 10
void main()
{
int *a,*b,size, del,j=0,i;
printf("enter the size of the array
");
scanf("%d",&size);
a=(int*)malloc(size*sizeof(int));
b=(int*)malloc(size*sizeof(int));
for(i=0;i<=size-1;i++)
{
printf("enter the value in an array
");
scanf("%d",&a[i]);
}
printf("enter the value to be deleted
");
scanf("%d", &del);
for(i=0;i<=size-1;i++)
{
if(a[i]!=del)
{
b[j]=a[i];
j++;
}
}
for(i=0;i<j;i++)
printf("%d
", b[i]);

}

Source: CoolInterview.com



Posted by: bhanu

Contact bhanu Contact bhanu

Source: CoolInterview.com

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int ar[10],i,loc;
cout<<"enter array";
for(i=0;i<10;i++)
cin>>a[i];
cout<<"enter loc to be deleted";
cin>>loc;
for(i=loc;i<10;i++)
a[i]=a[i+1];
cout<<"
array after deletion";
for(i=0;i<9;i++)
cout<<a[i];
getch();
}
Source: CoolInterview.com



Posted by: meena

Contact meena Contact meena

Source: CoolInterview.com

#define MAX 5
void main()
{
int input[MAX]={1,2,3,4,5};
int *output;
int key,c;
int* fun(int[],int);
clrscr();
printf("THE ELEMEST U WANT TO DELETE");
scanf("%d",&key);
output=(int*)malloc(sizeof(int)* (MAX-1));
output=fun(input,key);
printf("after deletion:");
for(c=0;c<MAX-1;c++)
printf("%d ",*(output+c));
getch();
}
int* fun(int temp1[],int hold)
{

static int temp2[MAX-1];
int index2=0;
int count;
for(count=0;count<MAX;count++)
if(temp1[count]!=hold)
temp2[index2++]=temp1[count];
return temp2;
}
Source: CoolInterview.com



Posted by: RAJU SAHANI

Contact RAJU SAHANI Contact RAJU SAHANI

If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-

  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
  • Name :*
    Email Id :*
    Answer :*
    Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
    Process Verification Enter the above shown code: *
    Inform me about updated answers to this question

    Related Questions
    View Answer
    Write a program to insert an element in a linear array array?
    View Answer
    Does mentioning the array name gives the base address in all the integers?
    View Answer
    How would you use qsort() function to sort the name stored in an array of pointers to string?
    View Answer
    Write a program for n lines
    1 2 3 4 5
    16 17 18 19 6
    15 24 25 30 7
    14 23 22 21 8
    13 12 11 10 9
    View Answer
    What is the difference between null array and an empty array?
    View Answer
    Code for swapping of two numbers without using temporary variable using C.
    View Answer
    Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?


    View Answer
    Can the sizeof operator be used to tell the size of an array passed to a function?


    View Answer
    How to remove duplicate elements from an array

    View Answer
    How can you sort the elements of the array in descending order?
    View Answer
    Array is an lvalue or not?
    View Answer
    Can the size of an array be declared at runtime?
    View Answer
    Can the sizeof operator be used to tell the size of an array passed to a function?
    View Answer
    Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?
    View Answer
    When does the compiler not implicitly generate the address of the first element of an array?
    View Answer

    Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

    View ALL Arrays in C Interview Questions & Answers

    User Options
    India News Network

    Latest 20 Questions
    what is the maximum segment length of a 100Base-FX network?
    What is mesh topology?
    What is IPv6?
    What is one basic requirement for establishing VLANs?
    When it comes to networking, what are rights?
    What protocols fall under the TCP/IP Internet Layer?
    What is the role of IEEE in computer networking?
    What is sneakernet?
    Explain profile in terms of networking concept?
    What can be done to fix signal attenuation problems?
    What is one advantage of mesh topology?
    What do mean by tunnel mode?
    Explain the importance of authentication.
    How are IP addresses arranged and displayed?
    What is the importance of Encryption on a network?
    What is multicast routing ?
    What is the importance of Encryption on a network?
    What is multicast routing?
    What is SMTP?
    What is the difference between CSMA/CD and CSMA/CA?



    Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

    Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

    Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

    MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
    MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

    GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

    IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
    IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

    SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
    SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




    Copyright ©2003-2016 CoolInterview.com, All Rights Reserved.
    Privacy Policy | Terms and Conditions



    Cache = 0.041016 Seconds