# C Programming – HackerRank Solution | Riping of Mangoes |

### (HackerRank) Write a Modular C Programming code to solve Riping of Mangoes. There are some mangoes in a mango tree. Every mango is about to ripe in few days. Hari notes the riping level of the mango.

Given a non-negative number find the position of the right – most set bit (1) in the binary representation of the number.

Input Format

First line contains a non-negative number.

Constraints

N>0 and N<= (2^31-1)

Output Format

Display the bit number, where the right most set bit is found in a single line.

Sample Input 0

```8
```

Sample Output 0

```3
```

Explanation 0

``````8 in binary representation is 1000. We clearly see that the set bit from RHS is at position 3. (right most bit is at position 0.)

3 2 1 0 -----> Bit position
1 0 0 0 -----> The bits
``````

Sample Input 1

```-9
```

Sample Output 1

`Invalid`

CODE:

```#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

struct node{
int data;
};
typedef struct node *NODE;
NODE create_node()
{
NODE newnode;
newnode=malloc(sizeof(struct node));
scanf("%d",&newnode->data);
return newnode;
}
NODE insert_end(NODE tail)
{
NODE newnode;
newnode=create_node();
if(tail==NULL)
{
tail=newnode;
}
else{
tail=newnode;
}
return tail;
}
NODE remaining(NODE tail,int *count)
{
NODE prev=tail;
*count=0;
do{
{
free(cur);
cur=next;
(*count)++;
}
else{
prev=cur;
cur=next;
}
}while(cur!=tail);
if(cur->data>next->data)
{
tail=prev;
free(cur);
(*count)++;
}
return tail;
}
void display(NODE tail)
{
do{
printf("%d ",cur->data);
}
int main() {
NODE tail=NULL;
int n;
scanf("%d",&n);
for(int i=0;i
OUTPUT
Congratulations, you passed the sample test case.

Click the Submit Code button to run your code against all the test cases.

Input (stdin)

6
29 54 66 12 67 10

29 54 12 10
2
Expected Output

29 54 12 10
2 Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, Stacks, Queues, Binary Trees, MISC, Solved model question papers & Hacker Rank all solutions on the below page:Top 100+ C Programming codes - KLE Technological University```

#### Welcome to FactsPrime

Sorry, We have detected that you have activated Ad-Blocker. Please Consider supporting us by disabling your Ad Blocker, It helps us in maintaining this website. To View the content, Please disable adblocker and refresh the page.

Thank You !!!