bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / assignment-primary / assignment-p-09.c

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 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror