Give a method to count the number of ones in a 32 bit number?
Answer Posted / jayaprakash
#include<stdio.h>
#include<conio.h>
main()
{
int i;
int n;
int count=0;
int j;
int res=0;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
for(j=15;j>=0;j--)
{ i=1;
i=i<<j;
res=i&n;
if(res!=0)
count++;
}
printf("\nNumber of ones is:%d",count);
getch();
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What does 1f stand for?
write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.
An organised method of depicting the use of an area of computer memory used to signify the uses for different parts of the memory a) swap b) extended memory c) memory map d) all of the above
What are the advantages of union?
What is data structure in c and its types?
In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?
What is a dynamic array in c?
In a switch statement, explain what will happen if a break statement is omitted?
Explain what are compound statements?
what are the facialities provided by you after the selection of the student.
How does normalization of huge pointer works?
Why header file is used in c?
How can you access memory located at a certain address?
Which is more efficient, a switch statement or an if else chain?
What is difference between structure and union in c?