In this program, we need to print the duplicate elements present in the array. This can be done through two loops. The first loop will select an element and the second loop will iteration through the array by comparing the selected element with other elements.
The array can be used as a HashMap. Problem in the below approach. This approach only works for arrays having at most 2 duplicate elements i.e It will not work if the array contains more than 2 duplicates of an element.
It works by creating a Set (which, by definition, cannot contain duplicates), initially containing all the elements in c .
Possible Duplicate:
Why can't variables be declared in a switch statement?
How can a variable be used when its definition is bypassed?
#include<stdio.h>
int main()
{
int a=1;
switch(a)
{ int b=20;
case 1: printf("b is %d\n",b);
break;
default:printf("%d\n",b);
break;
}
return 0;
}
ran on gcc 4.6.3, output not 20. What is going on here?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With