Question

In: Computer Science

(C programming) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each...

(C programming) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it’s not a duplicate of a number already read. Provide for the “worst case” in which all 20 numbers are different. Use the smallest possible array to solve this problem.

Your solution must include a function called isUnique() that returns 1 (true) if the number input is unique and 0 (false) otherwise . The implementation of this function must follow AFTER the implementation of main () in your .c file.

Output should be look like:

TEST SET 1

1 unique number

===============

Enter # 1 : 9

The number enetered is not in the valid range of 10 to 100

Enter # 1 : 101

The number enetered is not in the valid range of 10 to 100

Enter # 1 : 10

The number: 10 is unique

Enter # 2 : 10

Enter # 3 : 10

Enter # 4 : 10

Enter # 5 : 10

Enter # 6 : 10

Enter # 7 : 10

Enter # 8 : 10

Enter # 9 : 10

Enter # 10 : 10

Enter # 11 : 10

Enter # 12 : 10

Enter # 13 : 10

Enter # 14 : 10

Enter # 15 : 10

Enter # 16 : 10

Enter # 17 : 10

Enter # 18 : 10

Enter # 19 : 10

Enter # 20 : 10

All of the unique numbers found are:

  10

TEST SET 2

20 unique numbers

=================

Enter # 1 : 10

The number: 10 is unique

Enter # 2 : 20

The number: 20 is unique

Enter # 3 : 30

The number: 30 is unique

Enter # 4 : 9

The number enetered is not in the valid range of 10 to 100

Enter # 4 : 101

The number enetered is not in the valid range of 10 to 100

Enter # 4 : 40

The number: 40 is unique

Enter # 5 : 50

The number: 50 is unique

Enter # 6 : 60

The number: 60 is unique

Enter # 7 : 70

The number: 70 is unique

Enter # 8 : 80

The number: 80 is unique

Enter # 9 : 90

The number: 90 is unique

Enter # 10 : 100

The number: 100 is unique

Enter # 11 : 95

The number: 95 is unique

Enter # 12 : 85

The number: 85 is unique

Enter # 13 : 75

The number: 75 is unique

Enter # 14 : 65

The number: 65 is unique

Enter # 15 : 55

The number: 55 is unique

Enter # 16 : 45

The number: 45 is unique

Enter # 17 : 35

The number: 35 is unique

Enter # 18 : 25

The number: 25 is unique

Enter # 19 : 15

The number: 15 is unique

Enter # 20 : 11

The number: 11 is unique

All of the unique numbers found are:

  10  20  30  40  50

  60  70  80  90  100

  95  85  75  65  55

  45  35  25  15  11

Solutions

Expert Solution

Code

#include<stdio.h>
int isUnique(int a[],int b,int n);
int main()
{
    int n;
    int a[20]; //create array for unique elements
    int p=0;
    for(int i=1;i<=20;i++)
    {
        while(1)
        {
            printf("Enter # %d :",i);
            scanf("%d",&n);
            if(n<10 || n>100)
            {
                printf("The number enetered is not in the valid range of 10 to 100\n");
            }
            else
                break;
        }
        if(isUnique(a,p,n)) //calling function
        {
            printf("The number: %d is unique\n",n);
            a[p]=n;
            p++;
        }
    }
    printf("All of the unique numbers found are: ");
    for(int i=0;i<p;i++)
    {
        printf("%d ",a[i]);
        if(i%4==0 && i>0)
        printf("\n ");
    }
    return 0;
}
int isUnique(int a[],int b,int n)
{
    for(int i=0;i<=b;i++)
    {
        if(a[i]==n)
            return 0;
    }
    return 1;
}

Sample run

.


Related Solutions

problem 1 (Duplicate Elimination) code in JAVA please Use a one-dimensional array to solve the following...
problem 1 (Duplicate Elimination) code in JAVA please Use a one-dimensional array to solve the following problem: Write an application that inputs ten numbers, each between 10 and 100, both inclusive. Save each number that was read in an array that was initialized to a value of -1 for all elements. Assume a value of -1 indicates an array element is empty. You are then to process the array, and remove duplicate elements from the array containing the numbers you...
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements....
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements. Fill the array with random integers (use a loop). Neatly output each element in the one-dimensional array. Next convert your one-dimensional array of 24 elements into a two-dimensional array of 6 x 4 elements. Neatly output each element of the two-dimensional array. The values will be identical to the one-dimensional array – you’re just converting from one dimension to two.
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to fill the 2-dimensional array with (random numbers, range 0 - 30). The array has rows (ROW) and columns (COL), where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5....
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to find...
In C Write a program to read a one-dimensional array, print sum of all elements using...
In C Write a program to read a one-dimensional array, print sum of all elements using Dynamic Memory Allocation.
Write a Java program that will use a two-dimensional array to solve the following tasks: 1....
Write a Java program that will use a two-dimensional array to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5. Create a...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
5. Design a dynamic programming algorithm to solve the following problem. Input: An array A[1, ....
5. Design a dynamic programming algorithm to solve the following problem. Input: An array A[1, . . . , n] of positive integers, an integer K. Decide: Are there integers in A such that their sum is K. (Return T RUE or F ALSE) Example: The answer is TRUE for the array A = [1, 2, 3] and 5, since 2 + 3 = 5. The answer is FALSE for A = [2, 3, 4] and 8. Note that you...
Use the method of this section to solve the linear programming problem. Minimize   C = 2x...
Use the method of this section to solve the linear programming problem. Minimize   C = 2x − 3y + 6z subject to   −x + 2y − z ≤ 9 x − 2y + 2z ≤ 10 2x + 4y − 3z ≤ 12 x ≥ 0, y ≥ 0, z ≥ 0   The minimum is C =   at (x, y, z) =    .
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT