Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.


CS201 Assignment#2 Idea Solutions. Its not 100% sure solution. Try to make 100% by your self.....it’s just for help...Do not copy and past please.....

 

Idea Solution#1

 

you didn't specify the range of the numbers that can be input, I made it any number--would have been much simpler for the numbers 0 to 9 only

#include <iostream>
using namespace std;
void finddups(int[],int);
int main()
{int a[10],i;
for(i=0;i<10;i++)
   {cout"Enter the value of\narray element "i+1": ";
   cin>>a[i];
}
finddups(a,10);
system("pause");
return 0;
}
void finddups(int a[],int n)
{int i,j,k=0,b=0,c,dups[n];
bool done,first;
for(i=0;i<n;i++)
      dups[i]=0;
for(i=0;i<n-1;i++)
    {c=1;
     done=false;
     for(k=0;k<b;k++)
        if(a[i]==dups[k])
            {done=true;
            }
     if(!done)
        {first=true;
        for(j=i+1;j<n;j++)
            {if(a[i]==a[j])
               { c++;
                 if(first)
                    {first=false;
                      dups[b]=a[i];
                      b++;
                     }                 
               }
            }
         }
     if(c!=1)
          couta[i]" is repeated "c"\ntimes\n";
     
     }
    if(b==0)
         cout"There is no repetition in the array\n";
}        
    

Views: 57

Attachments:

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service