| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
copying numbers into an array without repetition
hi , please help me out with this issue,
i have two arrays A and B. For example A = { 3 , 3, 5,6 , 8, 9, 0, 8, 6} B = { } i have to copy numbers of array A into array B with out repetition and the program should give the count of each occurence of number(for eg 3's count is 2) please help me out with this, thanks in advance vamshi |
|
#2
|
|||
|
|||
|
Dunno if this could be counted at iteration or not. Its called recursion i think. When a function calls itself.
Code:
#include <iostream.h>
void copyarray (int*, int*, int);
int main ( void )
{
int a[9] = {1,2,3,4,5,6,7,8,9};
int b[9];
copyarray ( a ,b, 0 );
for (int i = 0; i < 9; i++ )
cout << b[i] << ' ';
return 0;
}
void copyarray (int *a, int *b, int i)
{
if (i <= 9)
{
b[i] = a[i];
copyarray ( a, b, i+1 );
}
}
|
|
#3
|
|||
|
|||
|
Could you specify what parts of the program can't be iterated? Iteration will have to be used in some part of the program but there's an approach using OOP that can make it look like there's no iteration within the main() function. Get back to me on those specifications.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > copying numbers into an array without repetition |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|