Question

Special array removal: Given an integer array a[8]= {2,3,5,7,11,13,17,19}, read in an integer k from the...

Special array removal:

Given an integer array a[8]= {2,3,5,7,11,13,17,19}, read in an integer k from the screen.
When k is a valid array index (i.e., between 0 and 7), move a[k] to the end of the array and push the array elements after a[k] one position up front. Print out the elements in the array after this removal. If k is not a valid array index, print out an error message.

For example, when k=2, the array will be changed to { 2,3,7,11,13,17,19,5 }

==> Please in C language <==
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

#include <stdio.h>

int main()
{
int a[]={2,3,5,7,11,13,17,19};
printf("Enter k: ");
int i,k,temp;
scanf("%d",&k);
if(k>7||k<0)
{
printf("Invalid k\n");
return 0;
}
temp=a[k];
for( i=k;i<8;i++)
{
a[i]=a[i+1];
}
a[7]=temp;
printf("Modified array is: ");
for(i=0;i<8;i++)
{
printf("%d ",a[i]);
}
return 0;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Special array removal: Given an integer array a[8]= {2,3,5,7,11,13,17,19}, read in an integer k from the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ==> Please In C Language <== Insert a value in a sorted array: Given an integer...

    ==> Please In C Language <== Insert a value in a sorted array: Given an integer array a[9] = { 2, 3, 5, 7, 11, 13, 17, 19 }, read in an integer k from the screen and insert k into the array so the new array remains sorted. Note that array a has size 9, but there are only 8 initial values. This ensures that no value will be lost after the insertion. For example, when k=12 , the...

  • Write a program that generates an array filled up with random positive integer number ranging from...

    Write a program that generates an array filled up with random positive integer number ranging from 60 to 100, and display it on the screen. After the creation and displaying of the array, the program displays the following: [R]everse [A]dd [S]earch E[xit] Please select an option:_ Then, if the user selects: - R (lowercase or uppercase): the program displays the reversed version of the array. - A (lowercase or uppercase): the program displays the sum of the elements of the...

  • write a java program Accept a positive integer n from keyboard and then create an array...

    write a java program Accept a positive integer n from keyboard and then create an array or arraylist containing n random elements within the range [-n,n). Print out the random array or arraylist, and then find out and print out the number of inversions and the maximum subarray (index range of the maximum subarray along with the maximum subarray sum) in the array or arraylist using divide and conquer, respectively. For example, suppose we accept integer 6 from keyboard, then...

  • 1. Write a C function named find that receives a one-dimensional array of type integer named...

    1. Write a C function named find that receives a one-dimensional array of type integer named arr and its size of type integer. The function fills the array with values that are the power of four (4^n) where n is the index. After that, the function must select a random index from the array and move the array elements around the element stored in the randomly selected index Example arr = [1, 4, 16, 64, 256) if the randomly selected...

  • Add reverse() method which reverses the content of array without using additional array. rotate(k) method which...

    Add reverse() method which reverses the content of array without using additional array. rotate(k) method which rotates left the content of array without using additional array by k elements. import java.util.*; * Implementation of the ADT List using a fixed-length array. * * if insert is successful returns 1, otherwise 0; * for successful insertion: * list should not be full and p should be valid. * * if delete is successful returns 1, otherwise 0; * for successful deletion:...

  • Write a C++ program that generates an array filled up with random positive integer number ranging...

    Write a C++ program that generates an array filled up with random positive integer number ranging from 15 to 20, and display it on the screen. After the creation and displaying of the array , the program displays the following: [P]osition [R]everse, [A]verage, [S]earch, [Q]uit Please select an option: Then, if the user selects: -P (lowercase or uppercase): the program displays the array elements position and value pairs for all member elements of the array. -R (lowercase or uppercase): the...

  • using C++ Write a program that: a) Inputs an integer n from the keyboard where n<=100....

    using C++ Write a program that: a) Inputs an integer n from the keyboard where n<=100. If n is out of range then print out an error message and ask for another input. This process repeats until a valid value for n is obtained. b) Inputs two 1D arrays of doubles A and B (of size n) from the keyboard. c) Inputs an integer k (from 1 to 3) from the keyboard. d) If k = 1 then it calculates...

  • Write a C PROGRAM that will read in 10 floating-point numbers from the keyboard and load...

    Write a C PROGRAM that will read in 10 floating-point numbers from the keyboard and load them into an array. Add up all the values and store the answer in a variable. Find the largest and smallest number in the array. Put each into its own variable. Print to the screen the sum, largest value, and smallest value. Copy the array to a second array in reverse order. Print out the second array. Read in 20 integer numbers, all in...

  • A mechanical turtle walks around a room under the control of a C++ program. Note: There...

    A mechanical turtle walks around a room under the control of a C++ program. Note: There is no animation of the turtle walking around the room The turtle holds a pen in one of two positions, up or down. When the pen is down the turtle draws out the shape as it moves. When the pen is up, the turtle moves about freely without writing anything. For this assignment you will write a program to simulate the operation of the...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT