assignment-p-09.c (783B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 /* Write a C program that includes a user-defined function named setBit with the signature 8 int setBit(int num, int position);. The function should set the bit at the specified position 9 (0-indexed) to 1 and return the modified number. */ 10 11 #include <stdio.h> 12 13 int setBit(int, int); 14 15 int main() 16 { 17 int num, position; 18 printf("Enter the number: "); 19 scanf("%d", &num); 20 printf("Enter the postion where you want to set the bit (0-indexed): "); 21 scanf("%d", &position); 22 printf("\nModified number= %d", setBit(num, position)); 23 return 0; 24 } 25 26 int setBit(int num, int position) 27 { 28 int mask = 1 << position; 29 return num | mask; 30 }