Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void setBit(int* mask, int n)
- {
- *mask |= (1 << n);
- }
- void eraseBit(int* mask, int n)
- {
- *mask &= ~(1 << n);
- }
- int isSet(int mask, int n)
- {
- return mask & (1 << n);
- }
- int onesCount(int mask)
- {
- int count = 0;
- for (int i = 0; i < sizeof(int) * 8; i++)
- {
- if (isSet(mask, i))
- {
- count++;
- }
- }
- return count;
- }
- int zerosCount(int mask)
- {
- return sizeof(int) * 8 - onesCount(mask);
- }
- int main()
- {
- int prisustviq = 0;
- int option;
- while (1)
- {
- printf("1. Napishi prisustvie\n");
- printf("2. Napishi otsustvie\n");
- printf("3. Information\n");
- printf("4. Exit\n");
- scanf("%d", &option);
- if (option == 1)
- {
- int n;
- printf("Nomer na uchenik: ");
- scanf("%d", &n);
- setBit(&prisustviq, n);
- }
- else if (option == 2)
- {
- int n;
- printf("Nomer na uchenik: ");
- scanf("%d", &n);
- eraseBit(&prisustviq, n);
- }
- else if (option == 3)
- {
- printf("Broi prisustviq: %d\n", onesCount(prisustviq));
- printf("Broi otsustviq: %d\n", zerosCount(prisustviq));
- }
- else if (option == 4)
- {
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement