Count Digits in Given Number

Problem: Program to count number of digits of a given number.

To count the digits do the following steps:

  1. Remove last digit of a number N by dividing it with 10.
  2. Increment the count by 1.
  3. Repeat steps 1 and 2 until the value of N becomes 0.
#include<stdio.h>

int main() {
  int num, countDigits=0;
  scanf("%d",&num);
  while(num!=0){
    num /= 10;
    countDigits++;
  }
  printf("%d",countDigits);
  return 0;
}