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

January 11, 2025 No Comments » Hits : 421






Problem Statement : Write a C Program to Find the Number of Digits in an entered number ?


#include<stdio.h>
#include<string.h>
void main()
{
int num,digits;
char ch[10];
printf("\nEnter the Number : ");
scanf("%d",&num);
sprintf(ch,"%d",num);
digits = strlen(ch);
printf("\nNumber of Digits : %d",digits);
getch();
}

Output:

Enter the Number : 1234
Number of Digits : 4

Incoming search terms: