Skip to content

Instantly share code, notes, and snippets.

@Moverr
Created May 3, 2023 19:14
Show Gist options
  • Save Moverr/eb7b958850930773ecc96eb44d56109f to your computer and use it in GitHub Desktop.
Save Moverr/eb7b958850930773ecc96eb44d56109f to your computer and use it in GitHub Desktop.
Write a function named hasStringMode that takes an array argument, and return 1 if the mode Value in its array occurs exactly once otherwise return 0;
#include <stdio.h>
int main(){
int x = 10;
int y =x++;
//int arra[] ={1,-29,8,5,-29,6};s
int arra[] ={1,2,3,4,7};
printf("belong %d",hasStringMode(arra));
return 1;
}
int hasStringMode(int x[]){
int len = sizeof(x);
int modeOcucrencies = 0;
int count = 0;
for(int index =0; index<len-(len/2); index++){
for(int index2 =len-(len/2); index2>0; index2--){
if(index != index2){
if(x[index] == x[index2]){
count =count +1;
printf("%d \n",x[index]);
}
}
}
if(count > 0){
modeOcucrencies = modeOcucrencies +1;
count =0;
}
}
if(modeOcucrencies !=1){
return 0;
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment