-->
Showing posts with label program to delete an element stored in an array. Show all posts
Showing posts with label program to delete an element stored in an array. Show all posts

program to delete an element stored in an array

using turbo c++ compiler
--------------------------------------------------------------------------------------------------------------
// program to delete an element stored in an array

#include <stdio.h>
#include<conio.h>
void main()
{
    int a[100],n,i,location,j;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d\n",i);
        scanf("%d",&a[i]);
    }
    printf("numbers are:\n");
    for(i=0;i<n;i++)
    {

        printf("%d\n",a[i]);
               
    }
    printf("enter number's location to be deleted\n");
    scanf("%d",&location);
    for(i=0;i<n;i++)
    {
        if(i==location-1)
        {
            for(j=i;j<=n-1;j++)
            a[j]=a[j+1];                                         
        }                                                         
         
       
    }
    printf("number after deleting particular, are:\n");
    for(i=0;i<=n-2;i++)
    {

        printf("%d\n",a[i]);
               
    }
    getch();
}

---------------------------------------------------------------------------------
using devc++/codeblocks/online compiler with return concept.
----------------------------------------------------------------------------------
// program to delete an element stored in an array

#include <stdio.h>

int main()
{
    int a[100],n,i,location,j;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d\n",i);
        scanf("%d",&a[i]);
    }
    printf("numbers are:\n");
    for(i=0;i<n;i++)
    {

        printf("%d\n",a[i]);
               
    }
    printf("enter number's location to be deleted\n");
    scanf("%d",&location);
    for(i=0;i<n;i++)
    {
        if(i==location-1)
        {
            for(j=i;j<=n-1;j++)
            a[j]=a[j+1];                                         
        }                                                         
           
    }
    printf("number after deleting particular, are:\n");
    for(i=0;i<=n-2;i++)
    {

        printf("%d\n",a[i]);
               
    }
    return 0;
}