Q20. Write a program to read a long integer from a user and count a number of digits of it.
==> Code goes like this :
/* Counting digits in a integer */
#include<stdio.h>
int main()
{
long long num;
int count=0;
printf("\n Enter a number:");
scanf("%lld",&num);
while(num!=0)
{
count++; //incrementing count
num/=10; //removing the last digit
}
printf("\n Total digit=%d",count);
return 0;
}
Output:
I have used Dev CPP to compile this program.
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
Home / Counting digits in a number in C /
Counting digits of integer in C /
Programs in C
/ Count a number of digit in a Number using C Programming
- Blogger Comment
- Facebook Comment
Subscribe to:
Post Comments
(
Atom
)
0 comments:
Post a Comment