Computer Science, asked by newcitytoo3, 11 months ago

write a c program to find the number of digits in a number? ​

Answers

Answered by codiepienagoya
0

Counts numbers in digits

Program:

#include<stdio.h> //include header file to use built-in function

int main() //defining main method

{

int number,total_number=0; //defining variables

printf("Enter any number : "); //message.

scanf("%d",&number); //input number from user

while(number!=0)//loop for count number

{

number = number/10; //collect quotient.

total_number++; //increment value by 1.

}

printf("Total digits: %d\n",total_number);

}

Output:

Enter any number : 786

Total digits: 3

Explanation:

  • In the above C language program, firstly include the header file, then define a main method.
  • Inside the main method, two integer variable is defined that is number and total_number.
  • The number variable is used for taking input from user and total_number is used to calculate the total digit of the given number.
  • Then a while loop is defined that uses both variables for count digits that are inserted by the user.
  • At the end of the loop the total_number variable print total digits.

Learn More:

  • Input two number in C: https://brainly.in/question/12886415
  • count digit in C : https://brainly.in/question/8485314
Similar questions