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);
- }
- //HW
- void funkci(int mask){
- for (int i = 0; i < sizeof(int) * 8; i++)
- {
- if (isSet(mask, i))
- {
- printf("%d ", i);
- }
- }
- }
- //HW
- void funkti(int mask){
- for (int i = 0; i < sizeof(int) * 8; i++)
- {
- if (!isSet(mask, i))
- {
- printf("%d ", i);
- }
- }
- }
- 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. ADD PRESENCE\n");
- printf("2. ADD ABSENCE\n");
- printf("3. INFORMATION\n");
- printf("4. EXIT\n");
- scanf("%d", &option);
- if (option == 1)
- {
- int n;
- printf("Enter student`s number: ");
- scanf("%d", &n);
- if(n >= 0 && n <= 32)
- {
- setBit(&prisustviq, n);
- }
- else
- {
- printf(" -ERROR- \n Invalid option! \n");
- }
- }
- else if (option == 2)
- {
- int n;
- printf("Enter student`s number: ");
- scanf("%d", &n);
- if(n >= 0 && n <= 32)
- {
- eraseBit(&prisustviq, n);
- }
- else
- {
- printf(" -ERROR- \n Invalid option! \n");
- }
- }
- else if (option == 3)
- {
- printf("1. OVERALL CLASS INFORMATION\n");
- printf("2. INFORMATION BY NUMBERS\n");
- int n;
- scanf("%d", &n);
- if(n == 1)
- {
- printf("Total number of presence students: %d\n", onesCount(prisustviq));
- printf("Total number of absence students: %d\n", zerosCount(prisustviq));
- }
- else if(n == 2)
- {
- printf("Presence students by number: ");
- funkci(prisustviq);
- printf("\n");
- printf("Absence students by number: ");
- funkti(prisustviq);
- printf("\n");
- }
- else
- {
- printf(" -ERROR- \n Invalid option! \n");
- }
- }
- else if (option == 4)
- {
- break;
- }
- else
- {
- printf(" -ERROR- \n Invalid option! \n");
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment