#include<stdio.h>
int main()
{
int i, n, position, a[100], item;
printf("How many Array Element you want to Enter\n");
scanf("%d " ,&n);
printf("Enter an Array Elements\n");
for(i=0; i<n; i++)
scanf("%d ", &a[i]);
printf("which element you want to delete\n");
scanf("%d" , &item);
for(i = 0; i < n; i++)
{
if(a[i] = = item)
{
position = i;
break;
}
}
if( i = = n)
{
printf("Element can not find in this array");
}
else
{
for(i = position; i < n-1; i++)
{
a[i] = a[i+1];
}
n--;
printf("The Resultant array After Deletion is\n");
for(i = 0; i < n; i++)
printf("%d " , a[i]);
}
return 0;
}
INPUT 1:
How many Array Element you want to Enter
5
Enter an Array Elements
11
22
33
44
77
which element you want to delete
44
OUTPUT 1:
The Resultant array After Deletion is
11 22 33 77
INPUT 2:
How many Array Element you want to Enter
5
Enter an Array Elements
11
22
33
44
77
which element you want to delete
88
OUTPUT 2:
Element can not find in this array
int main()
{
int i, n, position, a[100], item;
printf("How many Array Element you want to Enter\n");
scanf("%d " ,&n);
printf("Enter an Array Elements\n");
for(i=0; i<n; i++)
scanf("%d ", &a[i]);
printf("which element you want to delete\n");
scanf("%d" , &item);
for(i = 0; i < n; i++)
{
if(a[i] = = item)
{
position = i;
break;
}
}
if( i = = n)
{
printf("Element can not find in this array");
}
else
{
for(i = position; i < n-1; i++)
{
a[i] = a[i+1];
}
n--;
printf("The Resultant array After Deletion is\n");
for(i = 0; i < n; i++)
printf("%d " , a[i]);
}
return 0;
}
INPUT 1:
How many Array Element you want to Enter
5
Enter an Array Elements
11
22
33
44
77
which element you want to delete
44
OUTPUT 1:
The Resultant array After Deletion is
11 22 33 77
INPUT 2:
How many Array Element you want to Enter
5
Enter an Array Elements
11
22
33
44
77
which element you want to delete
88
OUTPUT 2:
Element can not find in this array
No comments:
Post a Comment