#include <stdio.h>
unsigned char modifyBit(unsigned char reg, int pos, int mode) {
// Write your code here
if( mode == 0){
reg &= ~(1<<pos);
}
else if( mode == 1){
reg |= (1<<pos);
}
return reg;
}
int main() {
unsigned char reg;
int pos, mode;
scanf("%hhu %d %d", ®, &pos, &mode);
printf("%d", modifyBit(reg, pos, mode));
return 0;
}
Solving Approach
Think like you are having two modes if it's mode 0 ,then you have to clear the bit at position (pos) in register , otherwise if it's mode 1 , then you have to set that position (pos) in the register.