#include <stdio.h>
unsigned char modifyBit(unsigned char reg, int pos, int mode)
{
// Write your code here
if(mode==1)
{
reg=reg|(1<<pos);
}
else
reg=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
In the question first of all we need to check if user is enter which mode for that using conditional if else after that if user enter 1 and reg ang pos then in the if condition we write set bit logic for that other wise write a clear bit logic in else part