Monday, February 15, 2016

Program to count the number of digits in a integer Number.

/*=================================================================================
**
**  File Name     : countDigit.c
**  Creation Date : Mon 15 Feb 2016 09:18:11 PM IST
**  Last Modified : Mon 15 Feb 2016 09:33:57 PM IST
**  Compoler      : gcc
**  Author        : Manoj Kumar Patra, manojpatra.sit@gmail.com
**  Organization  : SCIS, University of Hyderabad, India.
**
**===============================================================================*/

#include<stdio.h>
int main()
{
    printf("\n= = = = = = = = Count the Number of digits = = = = = = = = =");
    int no, count=0;
    printf("\nEnter the number to count the digits : ");
    scanf("%d", &no);
    int k=no;
    while(no)
    {
        no = no/10;
        count++;
    }
    printf("\nThe number of digits present in %d is : %d\n",k, count);
    printf("\n= = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n\n");
}

Output:

max@ubuntu:~/cprog$ gcc countDigit.c -o countDigit
max@ubuntu:~/cprog$ ./countDigit

= = = = = = = = Count the Number of digits = = = = = = = = =
Enter the number to count the digits : 467913

The number of digits present in 467913 is : 6

= = = = = = = = = = = = = = = = = = = = = = = = = = = = =

No comments:

Post a Comment