Q. Write a C program to delete a value or element in array and user should guide which value is deleted.
Ans.
/*c program for delete a number in array*/
#include<stdio.h>
#include<conio.h>
#define SIZE 50
int main()
{
int arr[SIZE];
int i,num,index;
printf("Enter total number of element in array : ");
scanf("%d", &num);
for(i=0; i<num; i++)
{
printf("Enter %d element : ",i+1);
scanf("%d",&arr[i]);
}
printf("\nEnter element number which you want to delete : ");
scanf("%d", &index);
if(index >= num+1)
printf("\nElement not found!!");
else
{
for(i=index-1; i<num-1; i++)
arr[i]=arr[i+1];
printf("\n-- After deletion new array list --\n\n");
for(i=0; i<num-1; i++)
printf("\t%d\n",arr[i]);
}
getch();
return 0;
}
/*************** Output *****************/
Related Programs:
Ans.
/*c program for delete a number in array*/
#include<stdio.h>
#include<conio.h>
#define SIZE 50
int main()
{
int arr[SIZE];
int i,num,index;
printf("Enter total number of element in array : ");
scanf("%d", &num);
for(i=0; i<num; i++)
{
printf("Enter %d element : ",i+1);
scanf("%d",&arr[i]);
}
printf("\nEnter element number which you want to delete : ");
scanf("%d", &index);
if(index >= num+1)
printf("\nElement not found!!");
else
{
for(i=index-1; i<num-1; i++)
arr[i]=arr[i+1];
printf("\n-- After deletion new array list --\n\n");
for(i=0; i<num-1; i++)
printf("\t%d\n",arr[i]);
}
getch();
return 0;
}
/*************** Output *****************/
Screen shot of delete element in array |
Related Programs:
please post respective flowcharts...
ReplyDelete