Sunday 10 January 2016

Deleting An Element from a Linear Array (Algorithm 4.3)


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int N;
    scanf("%d", &N);
    int LA[N], K, j, i;
    for(i=0; i<N; i++) scanf("%d", &LA[i]);
    scanf("%d", &K);
    for(j=K; j<N-1; j++) LA[j] = LA[j+1];
    N--;
    for(i=0; i<N; i++) printf("%d\t", LA[i]);
    printf("\n");
    return 0;
} 
 First input N = array element number.  ex. 8
Second input LA[i] = input N element one by one. ex. 1 2 3 4 5 6 7 8
Third input K = In which location I want to Delete.  ex. 3
Output ex. 1 2 3 5 6 7 8


0 comments:

Post a Comment

Note: only a member of this blog may post a comment.