Binod's Blog

Tag: Array Update

Array Update

by on Dec.14, 2010, under C & C++, DSA in C, Tutorial

//WAP to UPDATE element in an array using C and algorithm
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
int a[8]={1,2,3,4,5,6,7, },pos=0,val;
printf(“befor UPDATE: “);
for(int i=0;i<8;i++){
printf(“%d”,a[i]);
}
printf(“\n Enter the value and position of the element to UPDATE in array: “);
scanf(“%d %d”,&val,&pos);
printf(“after UPDATE: “);
pos=pos-1;
for(i=8;i<=pos;i–){
a[i+1]=a[i] ;
}
a[pos]=val;
for(i=0;i<8;i++){
printf(“%d”,a[i]);
}
getch();
return 0;
}

Leave a Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...