Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

ARRAY

IN
“C”
INSERT AN ELEMENT INTO AN ARRAY
#include <stdio.h>
int main()
{
Int Array[10], Position, i, Number, Value;
printf("\n Please Enter Number of elements in an array\n");
scanf("%d", &Number);
printf("\n Please Enter %d elements of an Array \n", Number);
for (i = 0; i < Number; i++)
{
scanf("%d", &Array[i]);
}
printf ("\n Please Enter the location of a Element you want to insert\n");
scanf ("%d", &Position);
printf("\n Please Enter the value of an Array Element to insert\n");
scanf("%d", &Value);
for (i = Number - 1; i >= Position ; i--)
{
Array[i+1] = Array[i];
}
Array[Position] = Value;
printf("\n Final Array after Inserting an Element is:\n");
for (i = 0; i <= Number; i++)
{
Remove an element from Array
#include <stdio.h>
int main()
{
 int array[100], position, c, n;
 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 delete element\n");
 scanf("%d", &position);
 if (position >= n+1)
  printf("Deletion not possible.\n");
 else
   {
for (c = position ; c < n - 1; c++)
   array[c] = array[c+1];
 printf("Resultant array:\n");
  for (c = 0; c < n - 1; c++)
 printf("%d\n", array[c]);
   }
   return 0;
Program to copy the elements of
one array into another array
#include<stdio.h>
 int main() {
   int arr1[30], arr2[30], i, num;
 printf("\nEnter no of elements :");
   scanf("%d", &num);
  printf("\nEnter the values :");
   for (i = 0; i < num; i++)
{
  scanf("%d", &arr1[i]);
   }
   for (i = 0; i < num; i++)
{
 arr2[i] = arr1[i];
   }
   printf("The copied array is :");
   for (i = 0; i < num; i++)
  printf("\narr2[%d] = %d", i, arr2[i]);
   return (0);
}
TWO DIMENSIONAL ARRAY
#include<stdio.h>
int main()
{
int disp[2][3];
int i, j;
for(i=0; i<2; i++)
{
for(j=0;j<3;j++)
{
printf("Enter value for disp[%d][%d]:", i, j);
scanf("%d", &disp[i][j]);
}}
printf("Two Dimensional array elements:\n");
for(i=0; i<2; i++)
{
for(j=0;j<3;j++)
{
printf("%d ", disp[i][j]);
{
printf("\n");
}}}

You might also like