Ask a Teacher



WRITE A PROGRAM TO READ A POSITIVE INTEGER THEN PRINT THE NO. OF DIGITS IN 125.

#include <stdio.h>
 int main()
{
 int n,count=0; printf("Enter an integer: ");
scanf("%d", &n);
while(n!=0)
{
n/=10; /* n=n/10 */ ++count;
 }
printf("Number of digits: %d",count);
 }
Note: This is only a hint to help you, try to modify it to get your output.


comments powered by Disqus