Question

C Programming 2) Write a function that removes the redundant values from the array and replaces...

C Programming

2) Write a function that removes the redundant values from the array and replaces them with -1

Example: A = {4, 1, 2, 3, 4, 4, 5, 6, 2, 7}

The array becomes: A = {4, 1, 2, 3, -1, -1, 6, -1, 7}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Coding

#include <stdio.h>//standard input output header file
#define size 10//define size here for array size
void redudent(int []);
int main()
{
     int arr[size]={4, 1, 2, 3, 4, 4, 5, 6, 2, 7},i;//declare variable here
   printf("print array before removing redudent \n");//output display message
   for(i=0;i<size;i++)
   {
   printf("%d ",arr[i]);//dispaly array
   }
   printf("\n");
   redudent(arr);
     return 0;
}
void redudent(int a[])
{
   int i,j;//declare variable
   //here is the removing redudent data
   for(i=0;i<size;i++)
   {
       int temp=a[i];
       for(j=i+1;j<size;j++)
       {
           if(temp==a[j])
           a[j]=-1;
       }
   }
   printf("print array after removing redudent \n");//output display message
   for(i=0;i<size;i++)
   {
   printf("%d ",a[i]);//dispaly array
   }
}

output:

if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........

Add a comment
Know the answer?
Add Answer to:
C Programming 2) Write a function that removes the redundant values from the array and replaces...
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
  • c programming Write a function that prints the values in the array that appear once Example:...

    c programming Write a function that prints the values in the array that appear once Example: A = {4, 1, 2, 3, 4, 4, 5, 6, 2, 7} Output: 1, 3, 5, 6, 7

  • C programming Write a function that accepts an array of integers as an input, and output...

    C programming Write a function that accepts an array of integers as an input, and output the sum of all values and the multiplication of all values. e.g. Suppose that the array contained the following values: 1 2 3 -4 5. The function should calculate and output the sum of values (i.e. 1+2+3+(-4)+5=7) and the multiplication of all values (i.e. 1*2*3*-4*5=-120). Start by carefully writing the function prototype - put some thought into this. Think about the good programming habits,...

  • Using C programming Write a function that reverses the elements of an array of integers so...

    Using C programming Write a function that reverses the elements of an array of integers so that the first becomes the last. Hint use a temporary variable for swapping values. Test with an odd and even number of elements

  • C programming!!C programming!!C programming!!C programming!!C programming!! C programming!!C programming!!C programming!!C programming!!C programming!! C programming!!C programming!!C programming!!C...

    C programming!!C programming!!C programming!!C programming!!C programming!! C programming!!C programming!!C programming!!C programming!!C programming!! C programming!!C programming!!C programming!!C programming!!C programming!! Q2 (20 marks): remembering state, conditions, functions Write a function that takes two arguments an array and the size of the array and returns a count of all of the numbers between 2 and 5 inclusive. The code below shows how your function will be called. int main(void) { int values[6]={1,2,4,5,3,6}; int size=6; printf("There are %d values between 2 and 5 (inclusive)\n",...

  • The answer need to write in C programming. QUESTION 2 Write a program using array to...

    The answer need to write in C programming. QUESTION 2 Write a program using array to generate a multiplication table based on the user's input. For example if user enter 5 as input then a multiply table for 1 to 5 is printed as output as shown in Figure Q2. There are three main steps in this program which are: Print rows (a) (b) Print columns Print multiplication of data inside table (c) Select C:\example1 \bin\Debuglexample 1.exe enter the value...

  • a) Write a function called print_doubles that prints the first n elements of an array of...

    a) Write a function called print_doubles that prints the first n elements of an array of doubles. Assume the array is long enough. Example: double v[5] = {1,2,3,4,5}; print_doubles(v, 5); // prints [1,2,3,4,5] b) Write a function with the following signature: void get_min_max(const double values[], int n, double *pmin, double *pmax); that returns in output parameters *pmin the value of the minimum element in array values and in *pmax the maximum element. Parameter n represents the size of array values....

  • daily21. Computing 1. C programming Please provide comments and write pre-condition and post-condition for the function....

    daily21. Computing 1. C programming Please provide comments and write pre-condition and post-condition for the function. Description Create a project called Daily21. Add a source file called daily21.c into the project. In this exercise, you will practice working with an array of integers. In the main function, you first need to create an integer array with 10 elements in t. Use a loop to read 10 integers from the user and store the values to the array (in the order...

  • C++ Programming 1. Write a function (header and body) that accepts an integer as an argument...

    C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....

  • Write a function replaceNums that replaces each element except the first and last by the larger...

    Write a function replaceNums that replaces each element except the first and last by the larger of its two neighbors. Your function should take two parameters, an integer array and the array length (in this order). Your function should not return or print anything. Examples int myArray[2] = {1, 5); → {1.9 int myArray 1 3(1); → {1} int myArray[3] = {1, 3, 5); → {1, 5.9 int myArray[3] = {5, 3, 1); → {5, 5, 1} int myArray[5] =...

  • C++ programming please Write a program that will display random numbers in order from low to...

    C++ programming please Write a program that will display random numbers in order from low to high. 1. Declare an integer array of size 100. Ask the user how many numbers to work with (n). It can be less than 100. 2. Generate random numbers from 10 to 50. 3. Write the random numbers to an output file named random.dat. Close the file. 4. Open random.dat for input and read the data values into your array. Pass your array to...

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