C code to count the total number of digit using for loop

Posted By: Matpal Media - 1:53 AM
#include<stdio.h>
int main(){
  int num,count=0;

  printf("Enter a number: ");
  scanf("%d",&num);

  for(;num!=0;num=num/10)
      count++;

  printf("Total digits is:  %d",count);

  return 0;
}

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.