Ask your own question, for FREE!
Computer Science 18 Online
OpenStudy (anonymous):

•Write a program to display the duplicate values in an array. Formulas Needed: None Final submission along with Code Documentation & Naming Style Sheet 1. Opening Documentation: the header block should include the following: •Program name/syntax •Description of what the program does •Summary of the problem's specifications and assumptions •License info (optional) •References to sources of additional information used •Parameters •Class/Program Invariant (ensure these conditions are true) •Algorithm(s) used (including any special notes) •Out

OpenStudy (anonymous):

I wrote the program for this but im not sure if it write and i dont understand what she asking to go with it

OpenStudy (anonymous):

this is a very classical problem for newbbies :P .. what it says is.. you have a sequence of numbers, this sequence propably includes number that appear more than once i the sequence.. the problem wants you to store and output these values.. what do you have in mind?

OpenStudy (anonymous):

do you want me post me program i wrote

OpenStudy (anonymous):

#include<stdio.h> int main() { const int MAXELEMENTS = 10; int intArray[MAXELEMENTS]; int temp=0; int j=0; int i=0; //getting user input for(i=0;i<MAXELEMENTS;i++) { printf("Enter %d of %d integer: ",i+1,MAXELEMENTS); scanf("%d",&intArray); } //sorting the array in ascendimg order for(i=0;i<MAXELEMENTS;i++) { for(j=MAXELEMENTS-1;j>i;j--) { if(intArray[j-1]>intArray[j]) { temp=intArray[j]; intArray[j]= intArray[j-1]; intArray[j-1]=temp; } } } //checking duplicate values printf("Duplicate values: \n"); int num=intArray[0]; for(int i=1;i<MAXELEMENTS;i++) { if(num==intArray) { printf("%d\n",intArray); } else num=intArray; } return 0; }

OpenStudy (anonymous):

There are many places where you're forgetting to index into your arrays. You need to specify which element you want to use in that array. There are 4 places you haven't done this.

OpenStudy (anonymous):

is threre anyone that can help me fix this

OpenStudy (anonymous):

/* code for print the duplicate values in integer array duplicate.c */ #include<stdio.h> #include<conio.h> void main() { int num[100],dup[100], n, i, j, count=0; clrscr(); //get the length of array printf("\nEnter the length of array:"); scanf("%d",&n); for(i=1;i<=n;i++) { //getting the array element printf("\n Enter the %d th array element:",i); scanf("%d",&num[i]); //finding duplicate here if(i>1) { for(j=1; j<i; j++) { if (num[i] == num[j]) { dup[count++]=num[i]; //printf("\ndup array=%d num array=%d",dup[--count],num[i]); } } } } //printing the element printf("\nThe duplicate elements are\n"); for(i=0;i<count;i++) { printf("%d \t",dup[i]); } getch(); }

OpenStudy (anonymous):

@gergott There are 3 places that you have intArray that you need to replace with intArray[i] There is one place you need to replace intArray with intArray[i-1] Apart from that, your code is completely correct.

OpenStudy (anonymous):

@georgott your program is very slow, because it uses an O(N^2) procedure, there is no need to scan the whole array n times to look for duplicates.You can just store for evey element the numbers of its appearances.This will be way faster

OpenStudy (anonymous):

and @gergott why on earth would you use bubble sort for sorting? :P

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!