/* This code is to set kth bit
submitted by Manish Gowda T
accomplished by leftshift and OR function*/
#include <stdio.h>
#include <stdint.h>
uint8_t set_bit(uint8_t reg, uint8_t pos) {
uint8_t setter=(1<<pos);
return reg | setter;
}
int main() {
uint8_t reg, pos;
scanf("%hhu %hhu", ®, &pos); // Accept register value and position
uint8_t result = set_bit(reg, pos);
printf("%u", result); // Output the result as an integer
return 0;
}
Solving Approach
first we lest shift to the position we need to set then we do OR operation