0% found this document useful (0 votes)
74 views3 pages

C Program for Set Intersection and Divisibility

The document contains code for two programs. The first program accepts two arrays as input, finds the intersection elements between the arrays, and displays the intersection. The second program accepts a limit as input, finds and displays numbers between 1 and the limit that are divisible by 3 and 5, divisible by either 3 or 5, and not divisible by 3 and 5, and calculates the sums of the latter two sets of numbers.

Uploaded by

rubdavid20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views3 pages

C Program for Set Intersection and Divisibility

The document contains code for two programs. The first program accepts two arrays as input, finds the intersection elements between the arrays, and displays the intersection. The second program accepts a limit as input, finds and displays numbers between 1 and the limit that are divisible by 3 and 5, divisible by either 3 or 5, and not divisible by 3 and 5, and calculates the sums of the latter two sets of numbers.

Uploaded by

rubdavid20
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Q1)

#include <stdio.h>

void getArray(int set1[10],int set2[10]){

int i;

printf("Enter the elements of set 1:");

for (i = 0; i <10; i++) {

scanf("%d",&set1[i]);

printf("Enter the elements of set 2:");

for (i = 0; i <10; i++) {

scanf("%d",&set2[i]);

int findintersection(int set1[10],int set2[10],int intersection[10]){

int i, j,numintvalues=0;

for (i=0;i<10; i++){

for (j = 0;j<10; j++){

if (set1[i]==set2[j]){

intersection[numintvalues]=set1[i];

numintvalues=numintvalues+1;

break;

return numintvalues;

void displayintvalue(int intersection[10],int numintvalues){

int i;

if(numintvalues>0){

printf("the intersection elements are the following:");

for(i=0;i<numintvalues;i++){
printf("%d ",intersection[i]);

}}

else{

printf("there is no intersection\n");

main() {

int i, j,intersection[10],numintvalues;

int set1[10],set2[10];

getArray(set1,set2);

numintvalues=findintersection(set1,set2,intersection);

displayintvalue(intersection,numintvalues);

Q2)

#include<stdio.h>

main()

int limit,i,j=0,sum=0,count=0;

printf("enter the limit value:");

scanf("%d",&limit);

if(limit>=10 && limit<=150){

printf("all nbrs divisible by 3 and 5:");

for(i=1;i<=limit;i++){

if(i%3==0 && i%5==0 ){

printf("%d ",i);

printf("\nall nbrs divisible by either 3 or 5:");

for(i=1;i<limit;i++){
if(i%3==0 ^ i%5==0){

printf("%d ",i);

sum=sum+i;

printf("\nsum of nbrs divisible by either 3 or 5 is %d",sum);

printf("\nthe numbers which are not divisible by 3 and 5:");

for(i=1;i<limit;i++){

if(i%3!=0 && i%5!=0){

printf("%d ",i);

count=count+i;

printf("\nthe sum of nbrs not divisible by 3 and 5 is:%d",count);

else{

printf("\nyour limit is not in the range of 10 and 150");

You might also like