Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define SIZE 5
- #define m_count(arr, res, type)\
- {\
- unsigned type mask;\
- type temp;\
- int i, count = 0;\
- type *p = (type *)arr;\
- \
- for(i=0; i < SIZE ; i++)\
- {\
- mask = 1;\
- temp = p[i];\
- while(mask)\
- {\
- if(temp & mask)\
- {\
- count++;\
- }\
- mask = mask << 1;\
- }\
- }\
- res = count;\
- }
- typedef enum {t_int, t_double, t_char} types;
- int my_count(void *, types);
- int main()
- {
- int i ,temp;
- int arr[SIZE];
- printf("Please enter numbers: ");
- for(i=0; i<SIZE; i++)
- {
- scanf("%d", &temp);
- arr[i] = temp;
- }
- my_count((void *)arr, t_int);
- return 0;
- }
- int my_count(void *data, types t)
- {
- int res = 0;
- if(t == t_int)
- {
- m_count(data, res, int);
- }
- if(t == t_char)
- {
- m_count(data, res, char);
- }
- printf("res bits: %d ", res);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement