n is the number of times you want to the iterate over the loop. In this case, n
ID: 3872322 • Letter: N
Question
n is the number of times you want to the iterate over the loop. In this case, n should be 10.
Write a C program that reads in two sets of numbers A and B, and calculates and print their difference of set A and B: A - B, complement of set A: Aand complement of set B: B . A -B is the set of elements that appear in A but not in B, and that is the set of every element that is not in A. The values in the sets are restricted to the range 0... 9 and should include the following functions within the program: void set difference(int *a, int *b, int n, int *difference); void setacomplement(int *a, int n, int *complement); set difference function:it should find the difference of the set represented by array a and set represented by array b and store the result in the set represented by array difference set complement function: it should find the complement of the set represented by array a store the result in the set represented by array complement. Both functions should use pointer arithmetic - not subscripting - to visit array elements. In other words, eliminate the loop index varables and all use of the operator in the function Do not declare an integer variable within your function and use that integer variable to iterate through the loop instead declare a pointer and use that pointer to iterate through the loop in the function: inti; Do not use the above code or anything similar in your functions but instead use a pointer to loop through the for loop! The program will read in the number of element in the first set, for example, 4, then read in the numbers in the set, for example, 3 6 8 9. The repeat for the second set. The two sets do not necessarily are of the same size The sets are stored using arrays of Os and 1s. Calculate the difference of A and B, and complements of the two sets and display the result. Sample input/output Please enter the number of elements in set A: 3 Enter the numbers in set A: 3 5 8 Please enter the number of elements in set B: 4 Enter the numbers in set B: 7 59 3 Output The difference of set A and B is: 8 The complement of set A is: 0 124679 The complement of set B is: 0 1 246 8Explanation / Answer
#include <stdio.h>
#include<stdio.h>
#define MAX 30
void create(int set[]);
void print(int set[]);
void difference(int set1[],int set2[],int set5[]);
int member(int set[],int x);
void complement(int set[]);
int main()
{
int set1[MAX],set2[MAX],set3[MAX];
set1[0]=set2[0]=set3[0]=0;
create(set1);
create(set2);
difference(set1,set2,set3);
print(set3);
complement(set1);
complement(set2);
return 0;
}
void create(int set[])
{
int n,i;
set[0]=0;
printf(" No. of elements in the set : ");
scanf("%d",&n);
printf("Enter set elements : ");
for(i=1;i<=n;i++)
scanf("%d",&set[i]);
set[0]=n;
}
void print(int set[])
{
int i,n;
n=set[0];
printf(" Members of the set :--> ");
for(i=1;i<=n;i++)
printf("%d ",set[i]);
}
int member(int set[],int x)
{
int i,n;
n=set[0];
for(i=1;i<=n;i++)
if(x==set[i])
return(1);
return(0);
}
void complement(int set[])
{
int i,j=0,k=0;
int set3[10];
set3[0]=0;
for(i=0;i<10;i++)
{
if(i!=set[j])
set3[k++]=i;
else
j++;
}
print(set3);
}
void difference(int set1[],int set2[],int set3[])
{
int i,n;
n=set1[0];
set3[0]=0;
for(i=1;i<=n;i++)
if(!member(set2,set1[i]))
set3[++set3[0]]=set1[i];
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.