To write a program in C to insert an element at end of an Array, First of all, we will find the last index of elements. After finding the last index we will add one index and insert an element.
Programming logic and working of insertion program in c at end
- Our Program will take size of the array and an element that need to insert in the array at end.
- Now to insert element at the end of array we will just insert at the last index directly.
- Becuase we already know the index number till element is filled in the array.
C program to insert an element at end of an Array
#include <stdio.h> void main() { int position, i, n, value,ch, arr[100]; printf("C Program to insert element at end of Array\n"); printf("First enter number of elements you want in Array\n"); scanf("%d", &n); arr[n]; for(i = 0; i < n; i++) { printf("Please give value for index %d : ",i); scanf("%d",&arr[i]); } printf("Let's Insert Element at end \n "); printf("Please give a number to insert at end \n"); scanf("%d", &value); arr[n] = value; printf("Element %d is inserted at %d index \n",value,n); printf("New Array is \n "); for(i = 0; i < n+1; i++) { printf("%d \t",arr[i]); } }
Output
[wpusb]
Also Prepare Below Important Question
- Sum of digits of Given Number in Java
- Hibernate Interview Questions for 2+ years of experience
- 68 Most Important Microservices Interview Questions
- 60 Most Important Git Interview Questions
- 50+ Mostly asked Java Interview Questions for 6 Years Exp.
- 60+ Mostly Asked Java Interview Questions for 4 Years Exp
- 60+ Mostly asked Java Interview Question for 3+ Years
- 60+ Spring Boot interview questions for 4+ years Exp.
- 60+ Mostly Asked Spring Boot Interview Questions for 3+ Yrs
- Scenario Based Java 8 Coding Interview Questions (For Experienced)
- Python Program to add two numbers without addition operator
- Mostly Asked Java Interview Questions For 2 Yrs Experience
- Find All Pairs in Array whose Sum is Equal to given number Using Java
- Java Program to find GCD of two Numbers using Recursion
- Python Program to Separate Characters in a Given String
- Python Program to add two number using Recursion
- Python Program to Find Highest Frequency Element in Array
- Python Program to Merge two Arrays
- Perform left rotation by two positions in Array Using Python
- Python Program to Delete Element at Given Index in Array
Interview Questions Categories
C Programming Interview Preparation
Core Java Programming Interview Preparation
- Core Java Programming Coding Questions
- Core Java Pattern Programming Questions
- Core Java Programming Interview Questions