Search



Wednesday, 11 February 2015

Digit counting

In this program, the number will be taken as input and since the loop will be executed till no. exists , so "while(n)" is used. Each time the no. will be divided by 10 till the value not less than 1 comes as a result and simultaneously each time the value of digit is increasing "digit++;".

Program to find no. of digits.

#include<stdio.h>
#include<conio.h>
void main()
{ int n,digit=0;
clrscr();
printf("\n to count no. of digits in program");
printf("\n\n enter the no. : ");
scanf("%d",&n);
while(n)
{ n = n/10;
digit++;
}
printf("\n\n no. of digits = %d",digit);
getch();
}




No comments:

Post a Comment

Guys if you think something is wrong or should be edit than please do comment.