3. Check if K-th Bit is Set

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>

int isKthBitSet(int n, int k) {
    // Write your code here
    int e;
    if (( n>>k)& 1 ==1){
        e=1;
        
    }else{
        e=0;
    }
    return e;
}
int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    printf("%d", isKthBitSet(n, k));
    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote