0% found this document useful (0 votes)
14 views2 pages

#Include: Distinct Elements in An Array Perfect

This C code takes in an array of integers as input, loops through the array, and prints out each distinct element only once by checking for duplicates. It first takes in the size of the array n, then the array elements. It then has two nested for loops - the outer loop iterates through each element, the inner loop checks if the current element is the same as any previous element, and breaks if so. If no duplicate is found, it prints the element. Example input and output are provided.

Uploaded by

Srinadh Shaik
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)
14 views2 pages

#Include: Distinct Elements in An Array Perfect

This C code takes in an array of integers as input, loops through the array, and prints out each distinct element only once by checking for duplicates. It first takes in the size of the array n, then the array elements. It then has two nested for loops - the outer loop iterates through each element, the inner loop checks if the current element is the same as any previous element, and breaks if so. If no duplicate is found, it prints the element. Example input and output are provided.

Uploaded by

Srinadh Shaik
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
You are on page 1/ 2

9/4/2019 Online C Compiler - Online C Editor - Run C Online - Online C Runner

Sponsored: Segment Send data to any tool without having to implement a new API every time. Get started

C
Project Name: Distinct elements in an array perfect
1 #include<stdio.h>
2 int main()
3 {
4 int i,n,j,distinct;
5 scanf("%d",&n);
6 int a[n];
7 for(i=0;i<n;i++)
8 {
9 scanf("%d",&a[i]);
10
11 }
12 for(i=0;i<n;i++)
13 {
14 distinct=0;
15 for(j=0;j<i;j++)
16 {
17 if(a[i]==a[j])
18 {
19 distinct=1;
20 break;
21 }
22 }
23 if(distinct==0)
24 printf("%d ",a[i]);
25
26 }/*
27 ip: 5
28 1 2 3 2 3
29 op: 1 2 3
30 */
31 }

   Execute Mode, Version, Inputs & Arguments

CommandLine Arguments

Stdin Inputs

Result

https://www.jdoodle.com/c-online-compiler/ 1/2
9/4/2019 Online C Compiler - Online C Editor - Run C Online - Online C Runner

https://www.jdoodle.com/c-online-compiler/ 2/2

You might also like