Contact Learn C
Copy

Program 107:Delete a specified integer in array

Program 107:
#include<stdio.h>
main()
{
    int i,size,position,delitem,flag=0;
    printf("Enter size\n");
    scanf("%d",&size);
    int a[size],temp[size-1];
    printf("Enter numbers in array\n");
    for(i=0;i<size;i++)
    {
        scanf("%d",&a[i]);
    }
    
    printf("Enter element to be deleted\n");
    scanf("%d",&delitem);
        for(i=0;i<size;i++)//find position of a number
    {
        if(a[i]==delitem)
        {
            position=i;
            flag=1;
        }    
        
    }
    if(flag==1)
    {
        for(i=0;i<size-1;i++)//deleting number in array
        {
        if(i<position)         
        {             
           temp[i]=a[i];         
           }        
        if(i>=position)
        {
         temp[i]=a[i+1];    
        }
        
        }
        
        printf("Array after deleting %d\n",delitem);
        for(i=0;i<size-1;i++)
        {
        printf("%d\n",temp[i]);
         }
    }
    else
    {
        printf("Number not found in array\n");
    } 
}
Explanation

//Coming Soon...

 Output:

Delete a specified integer in array

 

1 comment:

  1. factorial hundred In the last few days, the “factorial of 100” is one of the top subjects and a lot of maths geeks compute it using voice assistants such as Alexa, Shiri, etc.

    factorial hundred In the last few days, the “factorial of 100” is one of the top subjects and a lot of maths geeks compute it using voice assistants such as Alexa, Shiri, etc.

    factorial hundred In the last few days, the “factorial of 100” is one of the top subjects and a lot of maths geeks compute it using voice assistants such as Alexa, Shiri, etc.

    ReplyDelete

Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide