Untitled
unknown
plain_text
a year ago
954 B
12
Indexable
Question 1
#include<stdio.h>
int displayOddEven(int num)
{
int count = 0; // count will store binary digits
if (num > 0)
{
while (num > 0) // this while loop will convert decimal to binary
{
int remainder = num % 2;
num = num / 2;
count++;
printf("%d", count);
printf("\n");
}
if (count % 2 == 0) // if modulus is equal to 0 it will give even
{
printf("count of binary digit is even");
}
else
{
printf("count of binary digit is odd");
}
}
else // if user has given any negative value it will print the following content
{
printf("Please Enter the positive integer");
}
}
int main()
{
int num;
printf("enter the positive integer : ");
scanf("%d", &num);
int result = displayOddEven(num); // this will get called for the conversion
}Editor is loading...
Leave a Comment