0% found this document useful (0 votes)
7 views5 pages

2 - Distinct Elements of an array

The document presents a C program that identifies and prints all distinct elements from two input arrays, along with the total count of these distinct elements. It includes a function to compare the arrays and a main function to handle user input and output results. The example input arrays are {1,2,3,4,5} and {2,6,8,10}, resulting in distinct elements {1,3,4,5,6,8,10} with a total of 7.

Uploaded by

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

2 - Distinct Elements of an array

The document presents a C program that identifies and prints all distinct elements from two input arrays, along with the total count of these distinct elements. It includes a function to compare the arrays and a main function to handle user input and output results. The example input arrays are {1,2,3,4,5} and {2,6,8,10}, resulting in distinct elements {1,3,4,5,6,8,10} with a total of 7.

Uploaded by

ankurmourya99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Code for Interview

Code for Interview (Youtube)

Problem Statement

Program to print all distinct elements of given input arrays. Also print
the total of the distinct elements.

Input:

Arr1 = {1,2,3,4,5}

Arr 2 = {2,6,8,10}
Code for Interview

Solution in C Language

#include<stdio.h>

int Not_common (int *arr1, int *arr2, int l1, int l2){

int count =0, flag1, i, j;

for(i=0; i<l1; i++)

flag1=0;

for(j=0; j<l2; j++)

if(arr1[i] == arr2[j])

flag1=1; break;

}}

if(flag1 ==0)

count++;
Code for Interview

printf("%d,", arr1[i]);

for(i=0; i<l2; i++)

flag1=0;

for(j=0; j<l1; j++)

if(arr2[i] == arr1[j])

flag1=1;

break;

}}

if(flag1 ==0)

count++;

printf("%d,", arr2[i]);
Code for Interview

}}

return count;

int main(){

int len1=3,len2=3, result, i, j;

int arr1[10],arr2[10];

scanf("%d %d", &len1, &len2);

for(i=0; i<len1; i++)

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

for(i=0; i<len2; i++)

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

result = Not_common (arr1,arr2,len1,len2);

printf("\n %d", result);

return 0;

Output: {1,3,4,5,6,8,10} Total is 7


Code for Interview

You might also like