ok here is my code it runs perfect but it is too complex still to turn in is there anything simpler that i can do?
/***********************************************************************
assign7.cpp This program will take the imput of two sets of ten numbers and output the intersect of the two sets.
Inputs: input1 - ten numbers
input2 - ten numbers
Outputs: output1 - print out the set representing the intersection
Written by: Katie Stephens Date: October 28, 2009
************************************************************************/
#include "stdafx.h"
void input(int array[]);
int find_intersection (int array1[], int array2[], int intersection[]);
void print_array(int array[], int matches);
int _tmain(int argc, _TCHAR* argv[])
{
int array1[10];
int array2[10];
int intersection[10];
int matches;
printf ("Entering array 1:\n");
input(array1);
printf ("Entering array 2:\n");
input(array2);
matches = find_intersection(array1, array2, intersection);
print_array(intersection, matches);
return 0;
}
/***********************************************************************
void input(int my_array[]) This function will take the input of the first array
Inputs: input1 - ten numbers from the user
************************************************************************/
void input(int my_array[])
{
int i;
for (i = 0; i < 10; i++)
{
printf ("Please enter an integer.");
scanf ("%d", &my_array[i]);
}
}
/***********************************************************************
int find_intersection (int array1[], int array2[], int intersection[])
This function will take the input of the second array and find the intersection of the
first and second array.
Inputs: input1 - ten numbers from user
Outputs: output1 - the intersection of the two sets of arrays
************************************************************************/
int find_intersection (int array1[], int array2[], int intersection[])
{
bool duplicate = 0;
bool intersect = 0;
int i;
int j;
int k = 0;
for (i = 0; i < 10; i++) {
for (j = 0; j < i; j++) {
if (array1[j] == array1[i] && i != 0) {
duplicate = 1;
}
}
for (j = 0; j < 10; j++) {
if (array2[j] == array1[i]) {
intersect = 1;
}
}
if (intersect == 1 && duplicate == 0) {
intersection[k] = array1[i];
k++;
}
duplicate = 0;
intersect = 0;
}
return k;
}
/***********************************************************************
void print_array(int array[], int size) This function will print the intersection of the two arrays
Inputs: input1 - none
Outputs: output1 - print out the intersection of the two arrays.
************************************************************************/
void print_array(int array[], int size)
{
int i;
for (i = 0; i < size; i++) {
printf ("%d: %d\n", i + 1, array[i]);
}
}
Thread: need help
Forum: C