Assignment-csea3523


Submit solution

Points: 20 (partial)
Time limit: 1.5s
Memory limit: 64M

Author:
Problem type
Allowed languages
C

Write C Code to Delete an element from a specified position. Handle index error with message "error in index number"

Input 5 1 2 3 4 5 3

output 4 1 2 3 5


Comments


  • 0
    Daniyal_12  commented on May 3, 2023, 4:32 p.m.

    include <stdio.h>

    int main() { int n,i,p,t; scanf("%d",&n); int a[n]; for(i=0;i<=n-1;i++) { scanf("%d",&a[i]); }

    scanf("%d",&p); 
    t=a[p]; 
    
    if(p>n-1 ||p<0){ 
        printf("error in index number"); 
     } 
    else { 
        for(i=p;i<=n-2;i++) {
            a[i]=a[i+1]; 
          } 
    printf("%d\n",t); 
    for(i=0;i<=n-2;i++){ 
            printf("%d\n",a[i]); }
    }
    
    
    
    
    return 0;

    }


  • 0
    Amit_51  commented on May 3, 2023, 4:25 p.m.

    include <stdio.h>

    int main() { int n,i,p,t; scanf("%d",&n); int a[n]; for(i=0;i<=n-1;i++) { scanf("%d",&a[i]); }

    scanf("%d",&p); 
    t=a[p]; 
    
    if(p>n-1 ||p<0){ 
        printf("error in index number"); 
     } 
    else { 
        for(i=p;i<=n-2;i++) {
            a[i]=a[i+1]; 
          } 
    printf("%d\n",t); 
    for(i=0;i<=n-2;i++){ 
            printf("%d\n",a[i]); }
    }
    
    
    
    
    return 0;

    }


  • 0
    adityachowdary  commented on May 3, 2023, 3:17 p.m.

    include <stdio.h>

    int main(){ int n,i,p,t; scanf("%d",&n); int a[n]; for(i=0;i<=n-1;i++){ scanf("%d",&a[i]); } scanf("%d",&p); t=a[p]; if(p>n-1 ||p<0){ printf("error in index number"); } else{ for(i=p;i<=n-2;i++){ a[i]=a[i+1]; } printf("%d\n",t); for(i=0;i<=n-2;i++){ printf("%d\n",a[i]); } }

    }