Skip to content

Instantly share code, notes, and snippets.

@anisur3036
Last active November 1, 2022 12:40
Show Gist options
  • Save anisur3036/d305eb7c08cf1780d0c843c95913d40a to your computer and use it in GitHub Desktop.
Save anisur3036/d305eb7c08cf1780d0c843c95913d40a to your computer and use it in GitHub Desktop.
Find out all element of array are same in C
#include <stdio.h>
int main() {
// Write C code here
int i, n, m, unique = 0;
int value;
printf("Size of array: ");
scanf("%d", &n);
int arr[n];
for(i=0; i<n; i++) {
scanf("%d", &arr[i]);
}
for(i=0; i<n; i++) {
printf("%d ", arr[i]);
}
int first = arr[0];
for (i=1; i<n; i++) {
if (arr[i] == first) {
unique += 1;
}
}
printf("\n%d", (n-1));
if(unique == (n-1)) {
printf("\nYES");
} else {
printf("\nNO");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment