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("
Enter element number which you want to delete : ");
scanf("%d", &index);
if(index >= num+1)
printf("
Element not found!!");
else
{
for(i=index-1; i<num-1; i++)
arr[i]=arr[i+1];
printf("
-- After deletion new array list --
");
for(i=0; i<num-1; i++)
printf(" %d
",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("
Enter element number which you want to delete : ");
scanf("%d", &index);
if(index >= num+1)
printf("
Element not found!!");
else
{
for(i=index-1; i<num-1; i++)
arr[i]=arr[i+1];
printf("
-- After deletion new array list --
");
for(i=0; i<num-1; i++)
printf(" %d
",arr[i]);
}
getch();
return 0;
}
/*************** Output *****************/
Screen shot of delete element in array |
Related Programs:
0 comments:
Post a Comment