Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.
Login
Login
OnlineGDB Q&A
Questions
Unanswered
Tags
Ask a Question
Ask a Question
Count number of Ones in Array
0
votes
asked
Apr 10, 2020
by
Saba Noor
(
120
points)
I need to count number of Ones of a 32 bit array in C.
c
array
Please
log in
or register to answer this question.
1 Answer
+2
votes
answered
Apr 11, 2020
by
anu kanth sudharsanam
(
180
points)
#include <stdio.h>
int main()
{
char a[32];
int count=0,i;
printf("Enter your string");
scanf("%[^\n]s",a);
for(i=0;i<32;i++)
{
if(a[i]=='1')
{
count++;
}
}
printf("number of ones in an array is %d",count);
return 0;
}
Please
log in
or register to add a comment.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...