I have this void function that I call at a certain point on my main()
void calc(int dim){
int a[dim],i,j,temp;
for(int i=0;i<dim;i++)
{
printf("\n\n Type a number - [%d/%d]: \t",i+1,dim);
scanf("%d", &a[i]);
}
for(i=0;i<dim;i++)
{
for(j=i+1;j<dim;j++) {
if(a[i]==a[j])
{
continue;
}
else
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
printf("%d", a[j]);
}
}
}
for(i=0;i<dim;i++)
printf("%d", a[i]);
}
The input paramenter dim is the dimension of the array. The code you see works perfectly because it sorts the numbers inside my array.
If the user types 4 5 8 7 5 as input numbers, I want to have an output like this: 8 7 5 4. I must remove the repeated number, so I worte:
if(a[i]==a[j])
{
continue;
}
By the way the output is still 8 7 5 5 4. How could I fix this?
iin a loop looks like C supported by the old standard (C99), let alone the current standard (C2011, C11). Only certain widely used C compilers are still stuck in the C89 time-warp (yes, that's MSVC).