Last active
November 1, 2022 12:40
-
-
Save anisur3036/d305eb7c08cf1780d0c843c95913d40a to your computer and use it in GitHub Desktop.
Find out all element of array are same in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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