# Thread: CS201: Introduction to Programming Assignment No. 02 Spring 2010 May 6

1. ## CS201: Introduction to Programming Assignment No. 02 Spring 2010 May 6

Due Date:07/05/2010

Problem Statement: Finding the repeated elements in an array
You are required to write a program that takes 10 integer values in an array as input from user. After getting input, the program should find the elements with repetition and number of times each element is repeated.

Detailed Description:

1. Declare an integer type array.
2. Take input from user in the array i.e. 10 integer values.
3. Pass this array to a function which will calculate and display the number of times an element is repeated.
4. If the array contains elements with repetition, the program should only display the repeated elements and their count.
5. If there is no repetition in the array, the program should simply display the message “There is no repetition in the array”.

Sample Output 1
Enter the value of array element 1 : 8
Enter the value of array element 2 : 6
Enter the value of array element 3 : 2
Enter the value of array element 4 : 4
Enter the value of array element 5 : 2
Enter the value of array element 6 : 2
Enter the value of array element 7 : 7
Enter the value of array element 8 : 8
Enter the value of array element 9 : 5
Enter the value of array element 10 : 6

2 is repeated 3 times
6 is repeated 2 times
8 is repeated 2 times

Sample Output 2
Enter the value of array element 1 : 1
Enter the value of array element 2 : 3
Enter the value of array element 3 : 8
Enter the value of array element 4 : 7
Enter the value of array element 5 : 4
Enter the value of array element 6 : 9
Enter the value of array element 7 : 6
Enter the value of array element 8 : 5
Enter the value of array element 9 : 0
Enter the value of array element 10 : 2

There is no repetition in the array

3. Originally Posted by viki
Due Date:07/05/2010

Problem Statement: Finding the repeated elements in an array
You are required to write a program that takes 10 integer values in an array as input from user. After getting input, the program should find the elements with repetition and number of times each element is repeated.

Detailed Description:

1. Declare an integer type array.
2. Take input from user in the array i.e. 10 integer values.
3. Pass this array to a function which will calculate and display the number of times an element is repeated.
4. If the array contains elements with repetition, the program should only display the repeated elements and their count.
5. If there is no repetition in the array, the program should simply display the message “There is no repetition in the array”.

Sample Output 1
Enter the value of array element 1 : 8
Enter the value of array element 2 : 6
Enter the value of array element 3 : 2
Enter the value of array element 4 : 4
Enter the value of array element 5 : 2
Enter the value of array element 6 : 2
Enter the value of array element 7 : 7
Enter the value of array element 8 : 8
Enter the value of array element 9 : 5
Enter the value of array element 10 : 6

2 is repeated 3 times
6 is repeated 2 times
8 is repeated 2 times

Sample Output 2
Enter the value of array element 1 : 1
Enter the value of array element 2 : 3
Enter the value of array element 3 : 8
Enter the value of array element 4 : 7
Enter the value of array element 5 : 4
Enter the value of array element 6 : 9
Enter the value of array element 7 : 6
Enter the value of array element 8 : 5
Enter the value of array element 9 : 0
Enter the value of array element 10 : 2

There is no repetition in the array
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
void repeated_values(int[],int);
int main()
{
int a[10],f;
for(f=0;f<10;f++)
{
cout<<"Enter the value of array element "<<f+1<<": ";
cin>>a[f];
}
repeated_values(a,10);
system("pause");
return 0;
}
void repeated_values(int a[],int n)
{
int i,j,k=0,b=0,t,rpt[n];
bool first,ok;
for(i=0;i<n;i++)
rpt[i]=0;
for(i=0;i<n-1;i++)
{
t=1;
ok=false;
for(k=0;k<b;k++)
if(a[i]==rpt[k])
{
ok=true;
}
if(!ok)
{
first=true;
for(j=i+1;j<n;j++)
{
if(a[i]==a[j])
{
t++;
if(first)
{
first=false;
rpt[b]=a[i];
b++;
}
}
}
}
if(t!=1)
cout<<a[i]<<" is repeated "<<t<<" times\n";

}
if(b==0)
cout<<"There is no repetition in the array\n";
}

4. good solution but yah tu ab purani ho gai hai.