0% found this document useful (0 votes)
4 views4 pages

program Arrays

C programs

Uploaded by

gopiuma123456
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

program Arrays

C programs

Uploaded by

gopiuma123456
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1 .

program Arrays
2 #include <stdio.h>

• #include <conio.h>

• void main()

• {

• int arr[50], n, pos, item,i;

• // Input the size of the array

• printf("Enter the size of the array: ");

• scanf("%d", &n);

• // Input the elements of the array

• printf("Enter the elements of the array:");

• for ( i = 0; i < n; i++)

• {

• scanf("%d", &arr[i]);

• }

• // Input the position and value of the new element to be inserted

• printf("Enter the position and value of the new element to be inserted: ");

• scanf("%d%d", &pos, &item);

• // Shift the elements after the insertion position to the right

• for (i = n - 1; i >= pos-1; i--)

• {

• arr[i+1] = arr[i];

• }

• // Insert the new element at the desired position

• arr[pos-1] = item;

• // Increment the size of the array

• n++;

• // Print the updated array

• printf("The updated array is:");

• for (i = 0; i < n; i++)

• {
• printf("%d", arr[i]);

• }

• getch();

2. program

• #include <stdio.h>

• #include <conio.h>

• void main()

• {

• int array[100], position, i, n;

• printf("Enter the number of elements in array");

• scanf("%d", &n);

• printf("Enter %d elements", n);

• for (i = 0; i < n; i++)

• {

• scanf("%d", &array[i]);

• }

• printf("Enter the location where you wish to delete element");

• scanf("%d", &position);

• if (position >= n+1)

• {

• printf("Deletion not possible.");

• }

• else

• {

• for (i = position-1; i < n-1; i++)

• {

• array[i] = array[i+1]; //shifting

• }
• printf("Final array is");

• for (i = 0; i < n-1; i++)

• {

• printf("%d", array[i]);

• }

• }

• getch();

3. Program

• printf("Final array is");

• for (i = 0; i < n-1; i++)

• {

• printf("%d", array[i]);

• }

• }

• getch();

• // searching

• printf("\nElement to be searched:");

• scanf(" %d", &item);

• while( j < ub)

• {

• if( data[j] == item )

• { break;

• }

• j = j + 1;

• }

• printf("\nElement %d is found at %d position", item, j+1);

• getch();
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy