Search
 
SCRIPT & CODE EXAMPLE
 

C

C Program to Count Number of Digits in a Number

/* C Program to Count Number of Digits in a Number using While Loop */
#include <stdio.h>

int main()
{
  int Number, Reminder, Count=0;

  printf("
 Please Enter any number
");
  scanf("%d", &Number);

  while(Number > 0)
  {
     Number = Number / 10;
     Count = Count + 1;  
  }

  printf("
 Number of Digits in a Given Number = %d", Count);
  return 0;
}
Comment

c how many digits has a number

digits = (number == 0) ? 1 : (log10(number) + 1);
//or
while (number > 0)
{
	number /= 10;
	digits++;
}
//see: https://ideone.com/P1h8Ne
Comment

C number of digits in integer

int numberOfDigits = 1 + log10(number) // stores number of digits in integer
Comment

how to count digits and sum of digits in C

Enter the number
300
Given number = 300
Sum of the digits 300 = 3
 
 
Enter the number
16789
Given number = 16789
Sum of the digits 16789 = 31
Comment

PREVIOUS NEXT
Code Example
C :: take array as input in c 
C :: Prime Number Check Program in C 
C :: how to shutdown system c++ 
C :: Succ de ch 
C :: reattach screen linux 
C :: input in c 
C :: convert number to string c 
C :: pass the pointer to the function 
C :: unity set transform position code 
C :: c number to string 
C :: hi servicenow 
C :: c fork wait for child 
C :: why do we need return 0 in c? 
C :: how to sort assending in c 
C :: CL/cl.h: No such file or directory 
C :: how to print sizes of various data types of C 
C :: space x 
C :: C scanf() to read a string 
C :: vowel and consonant C 
C :: create role in psql with password 
C :: simple bootstrap form example 
C :: how to make a check bigger 
C :: c long to string 
C :: turn a char array into double C 
C :: set all pins as output for loop 
C :: sizeof file c 
C :: algorithm for dequeue 
C :: c comment 
C :: english to russian translation 
C :: example of source file 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =