Answers for "how to add values in an array"

2

how to insert an element from an array

int main()
{
   int array[100], position, c, n, value;
   printf("Enter number of elements in array\n");
   scanf("%d", &n);
 
   printf("Enter %d elements\n", n);
 
   for (c = 0; c < n; c++)
      scanf("%d", &array[c]);
 
   printf("Enter the location where you wish to insert an element\n");
   scanf("%d", &position);
 
   printf("Enter the value to insert\n");
   scanf("%d", &value);
 
   for (c = n - 1; c >= position - 1; c--)
      array[c+1] = array[c];
 
   array[position-1] = value;
 
   printf("Resultant array is\n");
 
   for (c = 0; c <= n; c++)
      printf("%d\n", array[c]);
 
   return 0;
}
Posted by: Guest on May-06-2021
15

add value to array javascript

var fruits = ["222", "vvvv", "eee", "eeee"];

fruits.push("Kiwi");
Posted by: Guest on May-21-2020
7

java add element to existing array

//original array
String[] rgb = new String[] {"red", "green"};
//new array with one more length
String[] rgb2 = new String[rgb.length + 1];
//copy the old in the new array
System.arraycopy(rgb, 0, rgb2, 0, rgb.length);
//add element to new array
rgb2[rgb.length] = "blue";
//optional: set old array to new array
rgb = rgb2;
Posted by: Guest on June-20-2020
4

how to add objects in array java

car redCar = new Car("Red");
car Garage [] = new Car [100];
Garage[0] = redCar;
Posted by: Guest on February-13-2020
0

how to add to an array

var ar = ['one', 'two', 'three'];
ar[3] = 'four'; // add new element to ar
Posted by: Guest on November-24-2020

Code answers related to "how to add values in an array"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language