Write a program to insert n element in the array and search for the element s in that array . If element found, replace that element with 100
#include<stdio.h>
int main()
{
int a[5];
int i,ins,ser,pos,r;
for(i=0;i<5;i++)
{
printf("Enter %d element:",i+1);
scanf("%d",&a[i]);
}
printf("\nEnter an element to insert:");
scanf("%d",&ins);
printf("\nEnter the position where you want to insert the element:");
scanf("%d",&pos);
for(i=5;i>=pos;i--)
a[i]=a[i-1];
a[pos-1]=ins;
for(i=0;i<=5;i++)
{
printf("%d\t",a[i]);
}
int count=0;
printf("\nEnter element to search:");
scanf("%d",&ser);
for(i=0;i<=5;i++)
{
if(ser==a[i])
{
count ++;
break;
}
else
count=0;
}
if(count>0)
{
printf("\n%d found at [%d]",ser,i);
printf("\nEnter the position where the element exist..");
scanf("%d",&r);
printf("\nElements after replacing the %d from the array.....",ser);
for(i=0;i<=5;i++)
{
if(i+1==r)
{
a[r-1]=100;
}
}
for(i=0;i<=5;i++)
{
printf("\n%d\t",a[i]);
}}
else
{
printf("\n%d not found",ser);}
}
Comments
Post a Comment