C Program to Count number of digits in number without using mod Operator



 c program to count number of digits in number without using mod operator

Learn C - C tutorial - c program to count number of digits in number without using mod operator - C examples - C programs

C Program to Count number of digits in number without using mod Operator

  • By using this C Program convert a decimal number into binary & count the number of 1s.
  • The program uses module operation and multiplication with base 2 operation for conversion.
  • It also uses modulo operation to check for 1’s and accordingly increments the count of 1s.
  • Here is source code of the C program to convert a decimal number to binary & count the number of 1s.

Sample Code

#include<stdio.h>
#include<string.h>
int main()
{
    int n=790, digits;
    char ch[10];
    printf("\nNumber : 790 ");
    sprintf(ch, "%d", n);
    digits = strlen(ch);
    printf("\nNumber of Digits : %d\n",digits);
    return(0);
}

Output

Number : 790 
Number of Digits : 3


View More Quick Examples


Related Searches to C Program to Count number of digits in number without using mod Operator