Question

Develop well-documented pseudo code that accepts an array of integers, A, of any size, then finds and removes all duplicate v

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

Initially calculate the size of the array and store it in a variable(.Here n= length of array).

step1: i=0 // initialize loop variable

step2: while (i<n) // run a loop from 0 to length of array

a) Set a flag to check when element deleted or not // flag = 1 initially

b). for ( j =0 ; j< i ; j++) // take another loop to run from 0 to i to check whether arr[i] is previously in array or not.

i). check if arr[ i ] equal to arr[ j ]

if arr[ i ] = = arr[ j ] then move front all array elements from i th index to last elements (i.e) for (k=i ; k< n-1 ;k++) { arr[k] = arr[k+1] }

ii). element deleted from array so make flag to 2.

c) Check if flag value changed or not . If flag = 1 i.e unchanged then increment loop variable (i = i+1).

d).else set i as i .(do not increment loop variable).

e). Repeat this process until loop completed

step 3. Stop.

Code:

#include <stdio.h>
int main()
{
int i=0,j,k,n;
printf("Enter the numebr of elements");
scantf("%d",&n);
int a[n];
for (i=0;i<n;i++){
printf("Enter element ");
scanf("%d",&a[i]);
}
printf("\nEntered array is :");
for (i=0;i<n;i++){
printf("%d ",a[i]);
}
i=0;
printf("%d",n);
while(i<n){
int flag =1;
for(j=0;j<i;j++){ // to check for duplicate element
if(a[i]==a[j]){
for(k=i;k<n-1;k++){ // to remove duplicate element from array
a[k]=a[k+1];
}
n=n-1;
flag=2;
break;
}
}
if (flag == 2 ){
i=i;
}
else{
i++;
}
  
}
printf("\n Final array after duplicate deletion");
for (i=0;i<n;i++){
printf("%d ",a[i]);
}
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Develop well-documented pseudo code that accepts an array of integers, A, of any size, then finds...
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
  • I need it in JAVA Write a program that randomly populates an array of size 100,...

    I need it in JAVA Write a program that randomly populates an array of size 100, sorts it, and then finds the median. The random numbers must be from 0-99 and all integer values. Also since there is an even set of numbers the median is found by taking the mean of the two middle numbers (In other words the 50th and 51st). You have to code your own sorting method. You may not use a built in java sorter....

  • I need to develop the 7 functions below into the main program that's given on top...

    I need to develop the 7 functions below into the main program that's given on top Write a C program to create array, with random numbers and perform operations show below. Il Project 3 (53-20). 1 Projects CS5,00 This file contains the function Programcution Dagine and one include <timo // Defining some constants definer_SIZE 20 define LOVE LIMIT 1 eine UPR UNIT define TALSE eine Tut 1 wold randomizery (int[], int, Int, int) wold pinay in. St, Int); En find...

  • How to write a recursive method named lessThanKFirst that receives an array of integers a and...

    How to write a recursive method named lessThanKFirst that receives an array of integers a and an integer k and rearranges the integers in a in such a way that all integers that are smaller than k come before any integers that are greater than or equal to k. As an example, suppose that a and k are: int[] a  = {35, 12, 57, 28, 49, 100, 61, 73, 92, 27, 39, 83, 52}; int k = 73; Then, the following...

  • The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random...

    The ExceptionLab class provided: – Creates an array of 100 elements and fills it with random numbers from 1 to 100. – It asks the user for an index value between 0 and 99. – Prints the element at that position. – If a number > 99 is entered by the user, the class will abort with an ArrayIndexOutOfBoundsException • Modify the ExceptionLab: – Add a try-catch clause which intercepts the ArrayIndexOutOfBounds and prints the message: Index value cannot be...

  • Suppose a binary tree data (in tiny written size) is stored in an array (A) as...

    Suppose a binary tree data (in tiny written size) is stored in an array (A) as given below and root is placed at “0”index. Note the array indices are in larger written size (0 to 74). Show the traversal data of the given tree for a)      In-Order Traversal b)     Post Order Traversal A 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 3 28 13 36 15 9 22 44 7 10 75 33 19 15...

  • 1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers...

    1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers of 1 through 15. Display your result back to the user with 2 decimal places (yes, 2 decimal places). You must implement your code using a for loop. The result should have the following format: The multiplication of 10*1 =10.00 The multiplication of 10*2 =20.00 The multiplication of 10'3=30.00 The multiplication of 10*15=150.00 2. (35 Points) Write MATLAB code to prompt a user for...

  • Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges...

    Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...

  • i need the solution in pseudo code please. 4 Dynamic Programmii Consider the following problem based on the transf...

    i need the solution in pseudo code please. 4 Dynamic Programmii Consider the following problem based on the transformation of a sequence (or collection) of coloured disks. Assume that you have a very large collection of disks, each with an integer value representing the disk colour from the range [0, cl. For example, the colour mapping might be: O-red, 1-yellow, 2-blue, 3-pink,. c-black For a given sequence of coloured disks eg.,0,1,2,3,4), at each time step (or iteration) you are only...

  • PLEASE SOLVE USING BASIC C++ CODEING PRINCIPLES PLEASE USE BASIC ARRAY, FUNCTION, AND LOOPING PRINCIPLES PLEASE...

    PLEASE SOLVE USING BASIC C++ CODEING PRINCIPLES PLEASE USE BASIC ARRAY, FUNCTION, AND LOOPING PRINCIPLES PLEASE COMPLETE ALL ASPECTS OF PAPER THANK YOU!!! Objectives To learn to code, compile and run a program containing ARRAYS. . Assignment Plan and code a modular program utilizing arrays. Use at least three functions to solve the problem. Input numbers from a textfile. Input the numbers, one by one. Store the even numbers in one array. Store the odd numbers in a second array....

  • Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D...

    Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D array of integers which is 10x10. 2. Prints out the contents of the 2D array after assigning the data to make sure correct data was assigned. 3. Figures out and prints out the square root of the sum of ALL the elements in the 2D array. 4. Figures out and prints out the average of ALL THE ELEMENTS in the 2D array. 5. Figures...

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