Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,152 questions

40,706 answers

573 users

How to insert an element into a specific position of int array in C

Booking.com | Official site | The best hotels, flights, car rentals & accommodations


82 views
asked Jul 6, 2020 by avibootz
edited Jul 22, 2020 by avibootz

1 Answer

0 votes
#include <stdio.h>

#define SIZE 10
  
int main()
{
	int arr[SIZE] = {4, 6, 2, 8, 9, 5, 7};
	int element = 1, pos = 3;

	for (int i = SIZE; i >= pos; i--) {
          arr[i] = arr[i-1];
	}
        
	arr[pos - 1] = element;
        
	for (int i = 0; i < SIZE; i++) {
		printf("%d ", arr[i]);
	}

    return 0;
}
  
  
  
/*
run:
  
4 6 1 2 8 9 5 7 0 0
  
*/

 





answered Jul 6, 2020 by avibootz

Related questions

2 answers 104 views
1 answer 75 views
1 answer 72 views
1 answer 67 views
2 answers 120 views
...