Friday, 5 May 2017

Program to count the number of digits of an integer in c programming

C program to count number of digits in an integer is an important question that often asked to check that whether our knowledge is good or not in c++

so, here we are sharing some codes for counting the numbers of digits in an integer. using these codes you can count the number of digits in an integer in different ways.

simple c program to count the number of digits of an integer using while loop

#include <stdio.h>
int main()
{
     long int a;
    int b = 0;

    printf("Enter an integer: ");
    scanf("%lld", &a);

    while(a != 0)
    {
        // a = a/10
        a /= 10;
        ++b;
    }

    printf("Number of digits: %d", b);
}

Program to count the number of digits of an integer in c programming


Program to count the number of digits of an integer in c programming


Another program to check this problem(Program to count the number of digits of an integer in c programming)


C Program to Count Number of Digits in an Integer using for loop


#include<stdio.h>
int main(){
  long long int a,b=0;

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

  for(;a!=0;a=a/10)
      b++;

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

  return 0;
}

Program to count the number of digits of an integer in c programming
Program to count the number of digits of an integer in c programming

Program to count the number of digits of an integer in c programming

If you like the program "Program to count the number of digits of an integer in c programming " do share with your friends and leave a comment.

2 comments:

Post a Comment