C program that receives a positive float number and divides it by two until the result is less than or equal to zero
###### Posted by Samath
Last Updated: June 12, 2015

Write a C program that receives a positive float number and divides it by two until the result is less than or equal to zero. Print the number of iterations required to meet the specification.

Code:

```#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char *argv[])
{
float x;
int count=0;
float t;

printf("Enter a number: ");
scanf("%f" ,&x);

if(x<=0)
{
printf("Invalid!\n");
exit(0);
}
else
{
do
{
t=x/2;
x=t;
count++;
}
while(!(x<=0));
printf("Number of iterations:%d\n ", count);
}
return 0;
}```

###### C program that determines if a number is equal to zero
Samath | Nov 07, 2014
###### C program that receives 10 float numbers from the console and sort them in nonascending order
Samath | Jun 01, 2015
###### C program that receives an integer number and determines if it is a prime number
Samath | Jun 01, 2015
###### JavaScript program that divides an array into chunks of a specified size
SceDev | Feb 24, 2024
###### C++ program that adds, subtracts, multiplies, or divides two integers
Samath | Nov 04, 2014
###### Write a function in C called RectArea() that returns an integer value equal to the area of the given rectangle
Samath | May 04, 2016
###### C program that multiplies the matrix a by the matrix b and stores the result in the matrix c
Samath | May 04, 2016
###### C program that determines if a number is either positive, zero, or negative
Samath | Nov 07, 2014
###### C program that takes as input a positive fractional number and converts it to binary
Samath | Jan 01, 2017
###### Java program that prints the sum of the first ten positive integers
Samath | Jan 08, 2021
###### Java program that prints the product of the first ten positive integers
Samath | Jan 08, 2021
###### Java program that reads an integer and prints if it's positive or negative
Samath | Feb 11, 2021
###### Java program that reads a floating ­point number and prints zero if the number is zero. Otherwise, print positive or negative
Samath | Feb 11, 2021
###### C program that prompts the user for a positive integer and then computes the sum of all the digits of the number
Samath | May 04, 2016