I'm taking a c programming course, and I don't have any idea where to start on a project. The project is to take a series of denary numbers inputted by the user (between 0 and 1023, I think), determine which have the highest cardinality (the number of ones when it's written in binary), and print the lowest number in the series with the highest cardinality.
The project is designed to make us use user-defined functions. I have a few ideas on how to determine the cardinality, which i will detail below, but I'm not even sure if that will work, or how to assemble the rest of the program. If someone could give me some pointers that would be awesome.
My idea on how to calculate cardinality:
Code:
int num; /*A number from the user*/
int lcv; /*The loop control variable*/
int card; /*The cardinality of num*/
for(lcv = 10; lcv >= 0; lcv--)
{
if((num - (2^lcv)) >= 0)
num = num - (2^lcv);
card = card++;
}
printf("%d", card);