Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int solution(int N);
- int main(){
- printf(" %d ", solution(10));
- return 0;
- }
- int solution(int N){
- int number = 1041, count = 0, i, j, temp, gapIndex = 0, gapCount = 0;
- int binaryConvertArray[100], binaryGap[100];
- /*decimal to binary convert section*/
- while(number !=0 ){
- binaryConvertArray[count] = number % 2;
- number /=2;
- count++;
- }
- /* binary array reverse section*/
- j = count -1, i = 0;
- while(i < j){
- temp = binaryConvertArray[i];
- binaryConvertArray[i] = binaryConvertArray[j];
- binaryConvertArray[j] = temp;
- i++;
- j--;
- }
- for(i = 0; i < count; i++){ /*print binary to decimal number */
- printf(" %d ", binaryConvertArray[i]);
- }
- printf("\n");
- /*searching gap indexr*/
- for(i = 1; i < count; i++){
- if(binaryConvertArray[i] == 0){
- gapCount++;
- }
- if(binaryConvertArray[i] == 1){
- // printf("gapcount = %d \n", gapCount);
- binaryGap[gapIndex] = gapCount;
- gapCount = 0;
- gapIndex++;
- }
- }
- for(i = 0; i < gapIndex; i++){ /*print binary to decimal number */
- printf("a %d \n", binaryGap[i]);
- }
- if(gapIndex > 1){
- if(binaryGap[0] > binaryGap[1]){
- return binaryGap[0];
- }
- else{
- return binaryGap[1];
- }
- }
- else if(binaryGap[0] == 0){
- return 0;
- }
- else{
- return binaryGap[0];
- }
- // if(binaryGap[0] == 0){
- // return 0;
- // }
- // if (binaryGap[0] > binaryGap[1]) {
- // return binaryGap[0];
- // }
- // else{
- // return []
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement