assignment-p-09.c (647B)
1 /* Write a C program that includes a user-defined function named setBit with the signature 2 int setBit(int num, int position);. The function should set the bit at the specified position 3 (0-indexed) to 1 and return the modified number. */ 4 5 #include <stdio.h> 6 7 int setBit(int, int); 8 9 int main() 10 { 11 int num, position; 12 printf("Enter the number: "); 13 scanf("%d", &num); 14 printf("Enter the postion where you want to set the bit (0-indexed): "); 15 scanf("%d", &position); 16 printf("\nModified number= %d", setBit(num, position)); 17 return 0; 18 } 19 20 int setBit(int num, int position) 21 { 22 int mask = 1 << position; 23 return num | mask; 24 }