Question

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

void print_unique(int arr[], int size) {
    int i, j, count;
    for (i = 0; i < size; ++i) {
        count = 0;
        for (j = 0; j < size; ++j) {
            if (arr[i] == arr[j]) {
                count++;
            }
        }
        if (count == 1) {
            printf("%d ", arr[i]);
        }
    }
    printf("\n");
}

int main() {
    int arr[] = {4, 1, 2, 3, 4, 4, 5, 6, 2, 7}; // change this array to anything you want. this code will still work..
    int size = sizeof(arr)/ sizeof(int);
    print_unique(arr, size);
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
c programming Write a function that prints the values in the array that appear once Example:...
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 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}

  • 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....

  • 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,...

  • C programming! Write a program that reads integers until 0 and prints the sum of values...

    C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...

  • Write a C++ function printArray(A, m, n) that prints a mxn two dimensional array A of...

    Write a C++ function printArray(A, m, n) that prints a mxn two dimensional array A of integers, declared to be "int** A," to the standard output. Each of the rows should appear on a separate line. Your input will be as follows with the first two values being the number of rows and columns respectively. HINT: This is best done with one for-loop nested within another Sample 1/0 1: Input: 3 2 1 2 3 4 Ол 6 Output: 12...

  • Write a C++ function that prints an array, skipping over a number of elements. Use the...

    Write a C++ function that prints an array, skipping over a number of elements. Use the following header: void printArraySkip(int array[], int elems, int skip) { } Where 'array' is an input array of 'elem' integer elements, and 'skip' is the number of elements to skip over. For example, if the function is called like this: int array[6] = { 5, 7, 11, 12, 18, 19 }; printArraySkip(array, 6, 2); The output would be: 11 19 in c++. Thanks

  • Use C Programming DESCRIPTION Write a program that: Creates a Dimensional, integer array that holds 8...

    Use C Programming DESCRIPTION Write a program that: Creates a Dimensional, integer array that holds 8 values Prompts the user to enter 8 integers between 0 and 20 [inclusive) and stores the data in the array Prints the data in array abng with a histogram of the data as shown below. There is no requirement to validate the data. You must use a constant to declare your array and control any loops you need Sample Output: Enter 8 integer values...

  • Programming in C: Write a program that accepts an integer and two floating-point values and prints...

    Programming in C: Write a program that accepts an integer and two floating-point values and prints the sum of these values. Example: Input:12,13.14,6.7; Output:31.84. Use formatted I/O

  • Write a C++ function printArray(A, m, n) that prints an m × n two dimensional array...

    Write a C++ function printArray(A, m, n) that prints an m × n two dimensional array A of integers, declared to be “int** A,” to the standard output. Each of the m rows should appear on a separate line.

  • 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",...

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