Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
727 B
1
Indexable
Never
// Online C compiler to run C program online
#include <stdio.h>

int main() {
int array[20];
int distinctArray[20];
int dimDist=0;
int i,j;
int flag=0;

for(i=0; i<20; i++)
{
    printf("Inserisci il valore %d: ", i+1);
    scanf("%d", &array[i]);
}

// array [34] [2] [2] [16] .......
for(i=0; i<20; i++) //i = 4
{
    flag = 1; // flag = 1
    for(j=0; j<dimDist; j++) //dimDist = 2
    {
        if(array[i] == distinctArray[j]) // j = 2
        {
            flag = 0; //flag = 1
        }
    }
    
    if(flag == 1)
    {
        distinctArray[dimDist] = array[i]; //distinctArray [34] [2] [16]
        dimDist++; //dimDist = 3
    }
}

for(i=0; i<dimDist; i++)
{
    printf("%d", distinctArray[i]);
}



    return 0;
}
Leave a Comment